{
  "scheduler": {
    "quartz-job-monitor-his-db": {
      //切片配置 
      "shireConfig": {
        "ownerId": "idc",
        "shredKey": "quartz-job-monitor-his-db",
        "shredType": "Table"
      }
   }
}

shreding_idc_resource_data_his.xml


<?xml version="1.0" encoding="utf-8"?>
<mappers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <mapper id="i_db_mysql" title="动态创建日志表 {suffix}202101 {suffix}20210101  20210101T01" cache="false" author="cbg">
    <sql connName="ConnIdc">
      <![CDATA[
       CREATE DATABASE IF NOT EXISTS fjcl_idc_@suffix DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
      ]]>
    </sql>
  </mapper>
  <mapper id="i_table_mysql" title="动态创建日志表 {suffix}202101 {suffix}20210101  20210101T01" cache="false" author="cbg">
    <sql connName="ConnIdc">
      <![CDATA[
        SET FOREIGN_KEY_CHECKS = 0;
            CREATE TABLE IF NOT EXISTS  `idc_resource_data_his_@suffix`

        SET FOREIGN_KEY_CHECKS = 1;
      ]]>
    </sql>
  </mapper>
</mappers>

db.provider.shirding.json

“shredMethod”: “Snowflake”, “shredPrimary”: “rl_id”,


{
  "shreding": {
    //全局配置 mkey
    "quartz-job-monitor-his-db": {
      // 存储如  mkey 或者 mapperKey  ,  数据在 db.provider.shirding.json
      "shredKey": null,
      "shredTableMKey": "shirding_idc_resource_data_his.i_table_mysql",
      "shredDbMKey": "shirding_idc_resource_data_his.i_db_mysql",
      //切片列   如时间列、自增列、数值列
      "shredColumn": null,
      //主键列   自增列、雪花算法列
      "shredPrimary": "rl_id",
      //切片数   求模切片
      "shredModNum": null,
      //切片规则 表   year  month  day   mod(求模)
      "shredTableRule": null,
      //切片规则 库   year  month  day   mod(求模)
      "shredDbRule": null,
      //切片类型   db-table     分库-分表     Unknown 不切片
      "shredType": "Table",
      //切片类型  Date  Snowflake Mod  Unknown 不切片
      "shredMethod": "Snowflake",
      // 分表 时间格式
      "shredTableFormat": "yyyyMMddHH",
      //替换表名 _@sufifx 替换为后缀名
      "repChars": [
        {
          "key": "idc_resource_data_his",
          "sortId": 1,
          "value": "idc_resource_data_his_@sufifx"
        }
      ]
    }
  }
}
  if (shredConfig.ShredMethod == ShredMethod.Snowflake)
                    {
                        //求模方式
                        var snowflake = RegexUtil.GetSnowflakeNumValue(parameters[shredConfig.ShredPrimary].ToString());
                        string tableSuffixTemp = "0";
                        try
                        {
                            var dataDate = Convert.ToDateTime(GidSnowflakeUtil.Analyze(Convert.ToInt64(snowflake.SnowflakeId)).DataDate);
                            tableSuffixTemp = dataDate.ToString(shredConfig.ShredTableFormat) ?? "0";
                        }
                        catch (Exception e)
                        {
                            tableSuffixTemp = "0";
                        }
                        lstGroup.Add(tableSuffixTemp);
                        parameters["tableSuffixTemp"] = tableSuffixTemp;
                    }

shredMethod”: “Date”, “shredColumn”: “save_time”,


{
  "shreding": {
    //全局配置 mkey
    "quartz-job-monitor-his-db": {
      // 存储如  mkey 或者 mapperKey  ,  数据在 db.provider.shreding.json
      "shredKey": null,
      "shredTableMKey": "shreding_idc_resource_data_his.i_table_mysql",
      "shredDbMKey": "shreding_idc_resource_data_his.i_db_mysql",
      //切片列   如时间列、自增列、数值列
      "shredColumn": "save_time",
      //主键列   自增列、雪花算法列
      "shredPrimary": "rl_id",
      //切片数   求模切片
      "shredModNum": null,
      //切片规则 表   year  month  day   mod(求模)
      //"shredTableRule": null,
      //切片规则 库   year  month  day   mod(求模)
      //"shredDbRule": null,
      //切片类型   db-table     分库-分表     Unknown 不切片
      "shredType": "Table",
      //切片类型  Date  Snowflake Mod  Unknown 不切片
      "shredMethod": "Date",
      // 分表 时间格式
      "shredTableFormat": "yyyyMMddHH",
      // 分表 时间格式
      "shredDbFormat": "yyyyMM"
    }
  }
}

   else if (shredConfig.ShredMethod == ShredMethod.Date)
                    {
                        string tableSuffixTemp = Convert.ToDateTime(parameters[shredConfig.ShredColumn]).ToString(shredConfig.ShredTableFormat);
                        lstGroup.Add(tableSuffixTemp);
                        parameters["tableSuffixTemp"] = tableSuffixTemp;
                    }
int count = await asyncProvider.DoAsync(new PFGlobalParameter { ShredConfig = sc.ShredConfig, OwnerId = sc.ShredConfig.OwnerId, SysId = sc.ShredConfig.SysId }, scT, resultT.Data, table);

resultC = resultC + _db.Execute(pfGlobal, schedulerConfig.ConnName, schedulerConfig.SaveSqlV.Replace("{table}", table), dicT);
文档更新时间: 2021-09-14 22:17   作者:admin