|
|
package main
|
|
|
|
|
|
import (
|
|
|
"dsBaseRpc/Const"
|
|
|
"dsBaseRpc/Utils/CommonUtil"
|
|
|
"dsBaseRpc/Utils/DateUtil"
|
|
|
"dsBaseRpc/Utils/DbUtil"
|
|
|
"dsBaseRpc/Utils/LdapUtil"
|
|
|
"dsBaseRpc/Utils/PinYinUtil"
|
|
|
"dsBaseRpc/Utils/RedisUtil"
|
|
|
"dsBaseRpc/models"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
var db = DbUtil.Engine
|
|
|
|
|
|
//声明结构体数组,最终提交
|
|
|
var arrayTBaseOrganization = make([]models.TBaseOrganization, 0)
|
|
|
var arrayTBaseTeacher = make([]models.TBaseTeacher, 0)
|
|
|
var arrayTSysLoginperson = make([]models.TSysLoginperson, 0)
|
|
|
var arrayTBaseRolePerson = make([]models.TBaseRolePerson, 0)
|
|
|
|
|
|
/**
|
|
|
功能:为指定身份的人员,批量生成账号
|
|
|
描述:生成登录账号 1:管理员,2:教师,3:学生,4: 家长
|
|
|
作者:黄海
|
|
|
时间:2020-05-30
|
|
|
*/
|
|
|
type LoginAccount struct {
|
|
|
LoginName string //登录名
|
|
|
Pwd string //密码,支持ldap
|
|
|
OriginalPwd string //初始密码
|
|
|
}
|
|
|
|
|
|
func GenerateLoginAccount(identityId int32, count int) []LoginAccount {
|
|
|
var loginPrefix = ""
|
|
|
switch identityId {
|
|
|
case 1:
|
|
|
loginPrefix = "sys"
|
|
|
break
|
|
|
case 2:
|
|
|
loginPrefix = "tea"
|
|
|
break
|
|
|
case 3:
|
|
|
loginPrefix = "stu"
|
|
|
break
|
|
|
case 4:
|
|
|
loginPrefix = "par"
|
|
|
break
|
|
|
}
|
|
|
//获取最大的此类身份
|
|
|
loginIdInt := RedisUtil.IncrBy(Const.LoginIdIntMax, 1)
|
|
|
//循环生成
|
|
|
result := make([]LoginAccount, 0)
|
|
|
for i := 0; i < count; i++ {
|
|
|
var loginAccount LoginAccount
|
|
|
loginAccount.LoginName = loginPrefix + CommonUtil.ConvertInt64ToString(CommonUtil.ConvertIntToInt64(i)+loginIdInt)
|
|
|
//休眠1毫秒,使随机数不一样
|
|
|
time.Sleep(1 * time.Microsecond)
|
|
|
loginAccount.OriginalPwd = CommonUtil.GenValidateCode(6)
|
|
|
loginAccount.Pwd = LdapUtil.GetLdapPassword(loginAccount.OriginalPwd)
|
|
|
result = append(result, loginAccount)
|
|
|
}
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:为指定行政区划生成或激活管理员
|
|
|
作者:黄海
|
|
|
时间:2020-06-08
|
|
|
*/
|
|
|
func AddVirtualManager(areaCode string, areaName string) {
|
|
|
//(1)插入基本人员信息
|
|
|
model := new(models.TBaseTeacher)
|
|
|
model.PersonId = CommonUtil.GetUUID()
|
|
|
model.IdentityId = 1
|
|
|
model.Xm = areaName + "管理员"
|
|
|
model.Xmpy = PinYinUtil.PinYin(model.Xm)
|
|
|
model.Cym = model.Xm
|
|
|
model.Xbm = "男"
|
|
|
model.Csrq = DateUtil.ConvertDate("1977-10-11")
|
|
|
model.Mzm = "1"
|
|
|
model.Zzmmm = "13"
|
|
|
model.Sfzjlxm = "4"
|
|
|
model.Sfzjh = "-1"
|
|
|
model.Xlm = "90"
|
|
|
model.Xwm = "0"
|
|
|
model.Zcm = "5"
|
|
|
model.Bzlbm = "9"
|
|
|
model.Cjny = DateUtil.ConvertDate("1999-09-01")
|
|
|
model.StageId = "Z"
|
|
|
model.SubjectId = "99"
|
|
|
model.Gwzym = "80"
|
|
|
model.Lxdh = "18888888888"
|
|
|
model.Dzxx = "xx@dsideal.com"
|
|
|
model.BUse = -1
|
|
|
model.BureauId = areaCode
|
|
|
model.OrgId = areaCode
|
|
|
model.SortId = 1
|
|
|
model.ProvinceCode = areaCode[0:2] + "0000"
|
|
|
model.CityCode = areaCode[0:4] + "00"
|
|
|
if areaCode[4:6] == "00" {
|
|
|
model.DistrictCode = "-1"
|
|
|
} else {
|
|
|
model.DistrictCode = areaCode
|
|
|
}
|
|
|
arrayTBaseTeacher = append(arrayTBaseTeacher, *model)
|
|
|
//(2)生成登录名和密码
|
|
|
accountArray := GenerateLoginAccount(1, 1)
|
|
|
modelLoginPerson := new(models.TSysLoginperson)
|
|
|
modelLoginPerson.Id = CommonUtil.GetUUID()
|
|
|
modelLoginPerson.LoginName = accountArray[0].LoginName
|
|
|
modelLoginPerson.Pwd = accountArray[0].Pwd
|
|
|
modelLoginPerson.OriginalPwd = accountArray[0].OriginalPwd
|
|
|
modelLoginPerson.IdentityId = 1
|
|
|
modelLoginPerson.PersonId = model.PersonId
|
|
|
modelLoginPerson.PersonName = model.Xm
|
|
|
modelLoginPerson.BUse = -1
|
|
|
arrayTSysLoginperson = append(arrayTSysLoginperson, *modelLoginPerson)
|
|
|
//(3)、t_base_role
|
|
|
modelBaseRolePerson := new(models.TBaseRolePerson)
|
|
|
modelBaseRolePerson.Id = CommonUtil.GetUUID()
|
|
|
var RoleId string
|
|
|
//省
|
|
|
if areaCode[2:4] == "00" {
|
|
|
RoleId = Const.ProvinceManager
|
|
|
} else if areaCode[4:6] == "00" {
|
|
|
RoleId = Const.CityManager
|
|
|
} else {
|
|
|
RoleId = Const.DistrictManager
|
|
|
}
|
|
|
modelBaseRolePerson.RoleId = RoleId
|
|
|
modelBaseRolePerson.IdentityId = 1
|
|
|
modelBaseRolePerson.PersonId = model.PersonId
|
|
|
modelBaseRolePerson.RuleId = areaCode
|
|
|
modelBaseRolePerson.BUse = -1
|
|
|
arrayTBaseRolePerson = append(arrayTBaseRolePerson, *modelBaseRolePerson)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:添加真实教育局的管理员
|
|
|
*/
|
|
|
func AddWardManager(orgId string, orgName string, areaCode string) {
|
|
|
//(1)插入基本人员信息
|
|
|
model := new(models.TBaseTeacher)
|
|
|
model.PersonId = CommonUtil.GetUUID()
|
|
|
model.IdentityId = 1
|
|
|
model.Xm = orgName + "管理员"
|
|
|
model.Xmpy = PinYinUtil.PinYin(model.Xm)
|
|
|
model.Cym = model.Xm
|
|
|
model.Xbm = "男"
|
|
|
model.Csrq = DateUtil.ConvertDate("1977-10-11")
|
|
|
model.Mzm = "1"
|
|
|
model.Zzmmm = "13"
|
|
|
model.Sfzjlxm = "4"
|
|
|
model.Sfzjh = "-1"
|
|
|
model.Xlm = "90"
|
|
|
model.Xwm = "0"
|
|
|
model.Zcm = "5"
|
|
|
model.Bzlbm = "9"
|
|
|
model.Cjny = DateUtil.ConvertDate("1999-09-01")
|
|
|
model.StageId = "Z"
|
|
|
model.SubjectId = "99"
|
|
|
model.Gwzym = "80"
|
|
|
model.Lxdh = "18888888888"
|
|
|
model.Dzxx = "xx@dsideal.com"
|
|
|
model.BUse = -1
|
|
|
model.BureauId = orgId
|
|
|
model.OrgId = orgId
|
|
|
model.SortId = 1
|
|
|
model.ProvinceCode = areaCode[0:2] + "0000"
|
|
|
model.CityCode = areaCode[0:4] + "00"
|
|
|
if areaCode[4:6] == "00" {
|
|
|
model.DistrictCode = "-1"
|
|
|
} else {
|
|
|
model.DistrictCode = areaCode
|
|
|
}
|
|
|
arrayTBaseTeacher = append(arrayTBaseTeacher, *model)
|
|
|
//(2)生成登录名和密码
|
|
|
accountArray := GenerateLoginAccount(1, 1)
|
|
|
modelLoginPerson := new(models.TSysLoginperson)
|
|
|
modelLoginPerson.Id = CommonUtil.GetUUID()
|
|
|
modelLoginPerson.LoginName = accountArray[0].LoginName
|
|
|
modelLoginPerson.Pwd = accountArray[0].Pwd
|
|
|
modelLoginPerson.OriginalPwd = accountArray[0].OriginalPwd
|
|
|
modelLoginPerson.IdentityId = 1
|
|
|
modelLoginPerson.PersonId = model.PersonId
|
|
|
modelLoginPerson.PersonName = model.Xm
|
|
|
modelLoginPerson.BUse = -1
|
|
|
arrayTSysLoginperson = append(arrayTSysLoginperson, *modelLoginPerson)
|
|
|
//(3)、t_base_role
|
|
|
modelBaseRolePerson := new(models.TBaseRolePerson)
|
|
|
modelBaseRolePerson.Id = CommonUtil.GetUUID()
|
|
|
var RoleId = Const.EduOrgManager
|
|
|
modelBaseRolePerson.RoleId = RoleId
|
|
|
modelBaseRolePerson.IdentityId = 1
|
|
|
modelBaseRolePerson.PersonId = model.PersonId
|
|
|
modelBaseRolePerson.RuleId = orgId
|
|
|
modelBaseRolePerson.BUse = -1
|
|
|
arrayTBaseRolePerson = append(arrayTBaseRolePerson, *modelBaseRolePerson)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:增加超级管理员
|
|
|
作者:黄海
|
|
|
时间:2020-06-08
|
|
|
*/
|
|
|
func AddSuperManager() {
|
|
|
//(1)插入基本人员信息
|
|
|
model := new(models.TBaseTeacher)
|
|
|
model.PersonId = CommonUtil.GetUUID()
|
|
|
model.IdentityId = 1
|
|
|
model.Xm = "超级管理员"
|
|
|
model.Xmpy = PinYinUtil.PinYin(model.Xm)
|
|
|
model.Cym = model.Xm
|
|
|
model.Xbm = "男"
|
|
|
model.Csrq = DateUtil.ConvertDate("1977-10-11")
|
|
|
model.Mzm = "1"
|
|
|
model.Zzmmm = "13"
|
|
|
model.Sfzjlxm = "4"
|
|
|
model.Sfzjh = "-1"
|
|
|
model.Xlm = "90"
|
|
|
model.Xwm = "0"
|
|
|
model.Zcm = "5"
|
|
|
model.Bzlbm = "9"
|
|
|
model.Cjny = DateUtil.ConvertDate("1999-09-01")
|
|
|
model.StageId = "Z"
|
|
|
model.SubjectId = "99"
|
|
|
model.Gwzym = "80"
|
|
|
model.Lxdh = "18888888888"
|
|
|
model.Dzxx = "xx@dsideal.com"
|
|
|
model.BUse = 1
|
|
|
model.BureauId = "-1"
|
|
|
model.OrgId = "-1"
|
|
|
model.SortId = 1
|
|
|
model.ProvinceCode = "-1"
|
|
|
model.CityCode = "-1"
|
|
|
model.DistrictCode = "-1"
|
|
|
arrayTBaseTeacher = append(arrayTBaseTeacher, *model)
|
|
|
//(2)生成登录名和密码
|
|
|
accountArray := GenerateLoginAccount(1, 1)
|
|
|
modelLoginPerson := new(models.TSysLoginperson)
|
|
|
modelLoginPerson.Id = CommonUtil.GetUUID()
|
|
|
modelLoginPerson.LoginName = accountArray[0].LoginName
|
|
|
modelLoginPerson.Pwd = LdapUtil.GetLdapPassword("123456")
|
|
|
modelLoginPerson.OriginalPwd = "123456"
|
|
|
modelLoginPerson.IdentityId = 1
|
|
|
modelLoginPerson.PersonId = model.PersonId
|
|
|
modelLoginPerson.PersonName = model.Xm
|
|
|
modelLoginPerson.BUse = 1
|
|
|
arrayTSysLoginperson = append(arrayTSysLoginperson, *modelLoginPerson)
|
|
|
|
|
|
//(3)、t_base_role
|
|
|
modelBaseRolePerson := new(models.TBaseRolePerson)
|
|
|
modelBaseRolePerson.Id = CommonUtil.GetUUID()
|
|
|
modelBaseRolePerson.RoleId = Const.SuperManager
|
|
|
modelBaseRolePerson.IdentityId = 1
|
|
|
modelBaseRolePerson.PersonId = model.PersonId
|
|
|
modelBaseRolePerson.RuleId = "100000"
|
|
|
modelBaseRolePerson.BUse = -1
|
|
|
arrayTBaseRolePerson = append(arrayTBaseRolePerson, *modelBaseRolePerson)
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
//禁用外键约束
|
|
|
sql := "SET foreign_key_checks = 0"
|
|
|
db.Exec(sql)
|
|
|
|
|
|
//删除部门的管理员
|
|
|
sql = "truncate table t_base_organization_manager"
|
|
|
_, err := db.Exec(sql)
|
|
|
if err != nil {
|
|
|
log.Fatal(err.Error())
|
|
|
}
|
|
|
|
|
|
//删除家长
|
|
|
sql = "truncate table t_base_parent"
|
|
|
_, err = db.Exec(sql)
|
|
|
if err != nil {
|
|
|
log.Fatal(err.Error())
|
|
|
}
|
|
|
|
|
|
//删除学生
|
|
|
sql = "truncate table t_base_student"
|
|
|
_, err = db.Exec(sql)
|
|
|
if err != nil {
|
|
|
log.Fatal(err.Error())
|
|
|
}
|
|
|
|
|
|
//家长表
|
|
|
sql = "truncate table t_base_parent"
|
|
|
_, err = db.Exec(sql)
|
|
|
if err != nil {
|
|
|
log.Fatal(err.Error())
|
|
|
}
|
|
|
//删除班级
|
|
|
sql = "truncate table t_base_class"
|
|
|
_, err = db.Exec(sql)
|
|
|
if err != nil {
|
|
|
log.Fatal(err.Error())
|
|
|
}
|
|
|
|
|
|
//清除组织机构
|
|
|
sql = "truncate table t_base_organization"
|
|
|
_, err = db.Exec(sql)
|
|
|
if err != nil {
|
|
|
log.Fatal(err.Error())
|
|
|
}
|
|
|
|
|
|
//删除人员角色关系
|
|
|
sql = "truncate table t_base_role_person"
|
|
|
db.Exec(sql)
|
|
|
_, err = db.Exec(sql)
|
|
|
if err != nil {
|
|
|
log.Fatal(err.Error())
|
|
|
}
|
|
|
|
|
|
//删除人员
|
|
|
sql = "truncate table t_base_teacher"
|
|
|
db.Exec(sql)
|
|
|
_, err = db.Exec(sql)
|
|
|
if err != nil {
|
|
|
log.Fatal(err.Error())
|
|
|
}
|
|
|
|
|
|
//登录表
|
|
|
sql = "truncate table t_sys_loginperson"
|
|
|
db.Exec(sql)
|
|
|
_, err = db.Exec(sql)
|
|
|
if err != nil {
|
|
|
log.Fatal(err.Error())
|
|
|
}
|
|
|
//初始化最大值为零
|
|
|
RedisUtil.SET(Const.LoginIdIntMax, "0", -1)
|
|
|
|
|
|
//增加超级管理员
|
|
|
AddSuperManager()
|
|
|
|
|
|
sql = "select * from t_gov_area"
|
|
|
list, _ := db.SQL(sql).Query().List()
|
|
|
//1、提取所有的省
|
|
|
for i := 0; i < len(list); i++ {
|
|
|
//省
|
|
|
if strings.HasSuffix(list[i]["area_code"].(string), "0000") {
|
|
|
var organization = models.TBaseOrganization{}
|
|
|
//添加省管理员
|
|
|
shengId := CommonUtil.GetUUID()
|
|
|
organization.SortId = int32(i + 1)
|
|
|
organization.BUse = -1
|
|
|
organization.Address = ""
|
|
|
organization.BureauId = shengId
|
|
|
organization.CityCode = ""
|
|
|
organization.DistrictCode = ""
|
|
|
organization.Fddbr = ""
|
|
|
organization.Fddbrdh = ""
|
|
|
organization.Fzr = ""
|
|
|
organization.Lxdh = ""
|
|
|
organization.ManageOrgId = ""
|
|
|
organization.MainSchoolId = ""
|
|
|
organization.MainSchoolType = -1
|
|
|
organization.OrgCode = ""
|
|
|
organization.OrgLat = 0
|
|
|
organization.OrgLng = 0
|
|
|
organization.ParentId = Const.ZeroGuid
|
|
|
organization.OrgId = shengId
|
|
|
organization.OrgName = list[i]["area_name"].(string) + "教育厅"
|
|
|
organization.ProvinceCode = list[i]["area_code"].(string)
|
|
|
organization.Szdcxlxm = "0"
|
|
|
organization.Xxbbm = "0"
|
|
|
organization.OrgType = 1
|
|
|
organization.AreaCode = list[i]["area_code"].(string)
|
|
|
arrayTBaseOrganization = append(arrayTBaseOrganization, organization)
|
|
|
|
|
|
//生成省管理员
|
|
|
AddVirtualManager(organization.AreaCode, list[i]["area_name"].(string))
|
|
|
|
|
|
//生成省教育厅管理员
|
|
|
AddWardManager(organization.OrgId, organization.OrgName, organization.AreaCode)
|
|
|
|
|
|
//放入省map
|
|
|
_ProvinceMap[list[i]["area_code"].(string)] = shengId
|
|
|
|
|
|
fmt.Printf("生成省:%s\n", list[i]["area_name"].(string))
|
|
|
} else if strings.HasSuffix(list[i]["area_code"].(string), "00") { //市
|
|
|
//市辖区不添加教育局
|
|
|
a := list[i]["area_name"].(string)
|
|
|
if strings.Index(a, "市辖区") < 0 {
|
|
|
//添加市教育局
|
|
|
var organization = models.TBaseOrganization{}
|
|
|
// 获得唯一id
|
|
|
shiId := CommonUtil.GetUUID()
|
|
|
organization.SortId = int32(i + 1)
|
|
|
organization.BUse = -1
|
|
|
organization.Address = ""
|
|
|
organization.BureauId = shiId
|
|
|
organization.CityCode = list[i]["area_code"].(string)
|
|
|
organization.DistrictCode = "-1"
|
|
|
organization.Fddbr = ""
|
|
|
organization.Fddbrdh = ""
|
|
|
organization.Fzr = ""
|
|
|
organization.Lxdh = ""
|
|
|
organization.MainSchoolId = ""
|
|
|
organization.MainSchoolType = -1
|
|
|
organization.OrgCode = CommonUtil.GetUUID()[0:30]
|
|
|
organization.OrgLat = 0
|
|
|
organization.OrgLng = 0
|
|
|
shengCode := list[i]["area_code"].(string)[0:2] + "0000"
|
|
|
organization.ParentId = Const.ZeroGuid
|
|
|
organization.OrgId = shiId
|
|
|
organization.ManageOrgId = _ProvinceMap[shengCode]
|
|
|
organization.OrgName = list[i]["area_name"].(string) + "教育局"
|
|
|
organization.ProvinceCode = shengCode
|
|
|
organization.AreaCode = list[i]["area_code"].(string)
|
|
|
organization.Szdcxlxm = ""
|
|
|
organization.Xxbbm = ""
|
|
|
organization.OrgType = 1
|
|
|
arrayTBaseOrganization = append(arrayTBaseOrganization, organization)
|
|
|
|
|
|
//生成市管理员
|
|
|
AddVirtualManager(organization.AreaCode, list[i]["area_name"].(string))
|
|
|
|
|
|
//生成市教育局管理员
|
|
|
AddWardManager(organization.OrgId, organization.OrgName, organization.AreaCode)
|
|
|
}
|
|
|
} else { //县区
|
|
|
//添加县区教育局
|
|
|
var organization = models.TBaseOrganization{}
|
|
|
// 获得唯一id
|
|
|
quId := CommonUtil.GetUUID()
|
|
|
organization.SortId = int32(i + 1)
|
|
|
organization.BUse = -1
|
|
|
organization.Address = ""
|
|
|
organization.BureauId = quId
|
|
|
cityCode := list[i]["area_code"].(string)[0:4] + "00"
|
|
|
organization.CityCode = cityCode
|
|
|
organization.DistrictCode = list[i]["area_code"].(string)
|
|
|
organization.Fddbr = ""
|
|
|
organization.Fddbrdh = ""
|
|
|
organization.Fzr = ""
|
|
|
organization.Lxdh = ""
|
|
|
organization.MainSchoolId = ""
|
|
|
organization.MainSchoolType = -1
|
|
|
organization.OrgCode = CommonUtil.GetUUID()[0:30]
|
|
|
organization.OrgLat = 0
|
|
|
organization.OrgLng = 0
|
|
|
organization.ParentId = Const.ZeroGuid
|
|
|
organization.OrgId = quId
|
|
|
shengCode := list[i]["area_code"].(string)[0:2] + "0000"
|
|
|
organization.ManageOrgId = organization.OrgId
|
|
|
organization.OrgName = list[i]["area_name"].(string) + "教育局"
|
|
|
organization.ProvinceCode = shengCode
|
|
|
organization.AreaCode = list[i]["area_code"].(string)
|
|
|
organization.Szdcxlxm = ""
|
|
|
organization.Xxbbm = ""
|
|
|
organization.OrgType = 1
|
|
|
arrayTBaseOrganization = append(arrayTBaseOrganization, organization)
|
|
|
|
|
|
//生成县区管理员
|
|
|
AddVirtualManager(organization.AreaCode, list[i]["area_name"].(string))
|
|
|
//生成县区教育局管理员
|
|
|
AddWardManager(organization.OrgId, organization.OrgName, organization.AreaCode)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//每个批次的大小
|
|
|
var batchSize =50
|
|
|
|
|
|
//批量插入1
|
|
|
var t1 = make([]models.TBaseOrganization, 0)
|
|
|
for i := range arrayTBaseOrganization {
|
|
|
t1 = append(t1, arrayTBaseOrganization[i])
|
|
|
if (i > 0 && (i+1)%batchSize == 0) || i == len(arrayTBaseOrganization)-1 {
|
|
|
_, err = db.Insert(t1)
|
|
|
if err != nil {
|
|
|
log.Fatalln(err.Error())
|
|
|
}
|
|
|
//清空数组
|
|
|
t1 = t1[0:0]
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//批量插入2
|
|
|
var t2 = make([]models.TBaseTeacher, 0)
|
|
|
for i := range arrayTBaseTeacher {
|
|
|
t2 = append(t2, arrayTBaseTeacher[i])
|
|
|
if (i > 0 && (i+1)%1000 == 0) || i == len(arrayTBaseTeacher)-1 {
|
|
|
_, err = db.Insert(t2)
|
|
|
if err != nil {
|
|
|
log.Fatalln(err.Error())
|
|
|
}
|
|
|
//清空数组
|
|
|
t2 = t2[0:0]
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//批量插入3
|
|
|
var t3 = make([]models.TBaseRolePerson, 0)
|
|
|
for i := range arrayTBaseRolePerson {
|
|
|
t3 = append(t3, arrayTBaseRolePerson[i])
|
|
|
if (i > 0 && (i+1)%1000 == 0) || i == len(arrayTBaseRolePerson)-1 {
|
|
|
_, err = db.Insert(t3)
|
|
|
if err != nil {
|
|
|
log.Fatalln(err.Error())
|
|
|
}
|
|
|
//清空数组
|
|
|
t3 = t3[0:0]
|
|
|
}
|
|
|
}
|
|
|
//批量插入4
|
|
|
var t4 = make([]models.TSysLoginperson, 0)
|
|
|
for i := range arrayTSysLoginperson {
|
|
|
t4 = append(t4, arrayTSysLoginperson[i])
|
|
|
if (i > 0 && (i+1)%1000 == 0) || i == len(arrayTSysLoginperson)-1 {
|
|
|
_, err = db.Insert(t4)
|
|
|
if err != nil {
|
|
|
log.Fatalln(err.Error())
|
|
|
}
|
|
|
//清空数组
|
|
|
t4 = t4[0:0]
|
|
|
}
|
|
|
}
|
|
|
//show variables like 'max_allowed_packet';
|
|
|
/**
|
|
|
//1073741824 --->最大值,即1G
|
|
|
//16777216 --->默认值,即16MB
|
|
|
MariaDB [(none)]> show variables like 'max_allowed_packet';
|
|
|
+--------------------+----------+
|
|
|
| Variable_name | Value |
|
|
|
+--------------------+----------+
|
|
|
| max_allowed_packet | 16777216 |
|
|
|
+--------------------+----------+
|
|
|
1 row in set (0.002 sec)
|
|
|
*/
|
|
|
//max_allowed_packet
|
|
|
/*
|
|
|
修改方法:
|
|
|
vi /etc/my.cnf.d/server.cnf
|
|
|
[mysqld]
|
|
|
max_allowed_packet = 1G
|
|
|
*/
|
|
|
|
|
|
//恢复外键约束
|
|
|
sql = "set foreign_key_checks = 1"
|
|
|
db.Exec(sql)
|
|
|
|
|
|
fmt.Println("恭喜,所有省市县(区)教育局生成成功!")
|
|
|
}
|