|
|
@@ -1,6 +1,11 @@
|
|
|
package samplessource
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
+ "github.com/tealeg/xlsx"
|
|
|
+ "os"
|
|
|
+ "time"
|
|
|
+
|
|
|
//"fmt"
|
|
|
"strconv"
|
|
|
|
|
|
@@ -63,142 +68,109 @@ func (s *SamplesSourceService) GetSampleSourceInfo(donors, testmain, donorsdetai
|
|
|
}
|
|
|
|
|
|
//样本源导入--动物
|
|
|
-//func (s *DonorsInfoService) InsertExcelDonors(excelpath, tablename, accode, createby string, createuserid int) (err error, warn string) {
|
|
|
-// svcdnote := extend.GetExtendService(utils.DBE)
|
|
|
-// notecount := svcdnote.GetNoteCount(accode) //获取扩展项目count
|
|
|
-// wherenote := " AccCode='" + accode + "'"
|
|
|
-// notelist := svcdnote.GetDNoteItemList(wherenote) //获取扩展项目List
|
|
|
-// flag := 0
|
|
|
-// dir, _ := os.Getwd()
|
|
|
-// excelpath = dir + excelpath
|
|
|
-// xlFile, _ := xlsx.OpenFile(excelpath)
|
|
|
-// var warn1 string
|
|
|
-// for sheetindex, sheet := range xlFile.Sheets { //循环页数
|
|
|
-// sheetrows := len(xlFile.Sheets[sheetindex].Rows)
|
|
|
-// for rowindex, row := range sheet.Rows { //循环行数
|
|
|
-// notefieldstr := ""
|
|
|
-// notevaluestr := ""
|
|
|
-// if rowindex == 0 {
|
|
|
-// continue
|
|
|
-// }
|
|
|
-// if row.Cells == nil || len(row.Cells) < 2 { //少于两列退出姓名不能为空
|
|
|
-// break
|
|
|
-// }
|
|
|
-// basestation := new(DonorsInfo)
|
|
|
-// for cellindex, cell := range row.Cells { //循环列数
|
|
|
-// if cellindex == 1 && len(cell.String()) == 0 { //姓名不能为空
|
|
|
-// flag = 1
|
|
|
-// break
|
|
|
-// }
|
|
|
-// if cell.String() != "" {
|
|
|
-// if cellindex == 0 {
|
|
|
-// basestation.IdCard = cell.String()
|
|
|
-// } else if cellindex == 1 {
|
|
|
-// basestation.Name = cell.String()
|
|
|
-// basestation.Sex = 2
|
|
|
-// } else if cellindex == 2 {
|
|
|
-// basestation.Telephone = cell.String()
|
|
|
-// } else if cellindex == 3 {
|
|
|
-// if cell.String() == "女" {
|
|
|
-// basestation.Sex = 1
|
|
|
-// } else if cell.String() == "男" {
|
|
|
-// basestation.Sex = 0
|
|
|
-// } else {
|
|
|
-// basestation.Sex = 2
|
|
|
-// }
|
|
|
-// } else if cellindex == 4 {
|
|
|
-// if cell.String() == "已婚" {
|
|
|
-// basestation.MaritalStatus = 1
|
|
|
-// } else if cell.String() == "未婚" {
|
|
|
-// basestation.MaritalStatus = 0
|
|
|
-// } else {
|
|
|
-// basestation.MaritalStatus = 2
|
|
|
-// }
|
|
|
-// } else if cellindex == 5 {
|
|
|
-// aa, _ := utils.StrTo(cell.Value).Float64()
|
|
|
-// basestation.Birthday = xlsx.TimeFromExcelTime(aa, false)
|
|
|
-// } else if cellindex == 6 {
|
|
|
-// basestation.Age, _ = utils.StrTo(cell.String()).Int()
|
|
|
-// } else if cellindex == 7 {
|
|
|
-// basestation.Mobile = cell.String()
|
|
|
-// } else if cellindex == 8 {
|
|
|
-// basestation.Email = cell.String()
|
|
|
-// } else if cellindex == 9 {
|
|
|
-// basestation.Nation = cell.String()
|
|
|
-// } else if cellindex == 10 {
|
|
|
-// basestation.Duty = cell.String()
|
|
|
-// } else if cellindex == 11 {
|
|
|
-// basestation.CompanyName = cell.String()
|
|
|
-// } else if cellindex == 12 {
|
|
|
-// basestation.ComeFrom = cell.String()
|
|
|
-// } else if cellindex == 13 {
|
|
|
-// basestation.HomeAddress = cell.String()
|
|
|
-// } else if cellindex == 14 {
|
|
|
-// basestation.AdmissionNumber = cell.String()
|
|
|
-// } else if cellindex == 15 {
|
|
|
-// basestation.PathologicalNum = cell.String()
|
|
|
-// } else if cellindex == 16 {
|
|
|
-// basestation.ClinicalDiagnosis = cell.String()
|
|
|
-// } else if cellindex == 17 {
|
|
|
-// basestation.Department = cell.String()
|
|
|
-// } else if cellindex == 18 {
|
|
|
-// aa, _ := utils.StrTo(cell.Value).Float64()
|
|
|
-// basestation.DiagnosticTime = xlsx.TimeFromExcelTime(aa, false)
|
|
|
-// } else if cellindex == 19 {
|
|
|
-// basestation.ClinicNum = cell.String()
|
|
|
-// } else if cellindex == 20 {
|
|
|
-// basestation.CheckPoint = cell.String()
|
|
|
-// } else if cellindex == 21 {
|
|
|
-// basestation.IllnessName = cell.String()
|
|
|
-// } else if cellindex == 22 {
|
|
|
-// basestation.InnerNo = cell.String()
|
|
|
-// } else if cellindex > 22 && cellindex < 23+notecount {
|
|
|
-// for i := 1; i < notecount+1; i++ {
|
|
|
-// if cellindex == 22+i {
|
|
|
-// notefieldstr = notefieldstr + "," + notelist[i-1].FieldName //扩展字段 因为cellindex可能小于21
|
|
|
-// notevaluestr = notevaluestr + ",'" + cell.String() + "'" //扩展名称
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if flag == 1 {
|
|
|
-// flag = 0
|
|
|
-// continue
|
|
|
-// }
|
|
|
+func (s *SamplesSourceService) InsertExcelAnimal(excelpath, tablename, accode, createby string, createuserid int) (err error, warn string) {
|
|
|
+ //svcdnote := extend.GetExtendService(utils.DBE)
|
|
|
+ //notecount := svcdnote.GetNoteCount(accode) //获取扩展项目count
|
|
|
+ //wherenote := " AccCode='" + accode + "'"
|
|
|
+ //notelist := svcdnote.GetDNoteItemList(wherenote) //获取扩展项目List
|
|
|
+ dir, _ := os.Getwd()
|
|
|
+ excelpath = dir + excelpath
|
|
|
+ xlFile, _ := xlsx.OpenFile(excelpath)
|
|
|
+ var warn1 string
|
|
|
+ fmt.Println("ssdsdsd",xlFile.Sheets)
|
|
|
+ for sheetindex, sheet := range xlFile.Sheets { //循环页数
|
|
|
+ sheetrows := len(xlFile.Sheets[sheetindex].Rows)
|
|
|
+ for rowindex, row := range sheet.Rows { //循环行数
|
|
|
+ notefieldstr := ""
|
|
|
+ notevaluestr := ""
|
|
|
+ if rowindex == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if row.Cells == nil || len(row.Cells) < 2 { //少于两列退出姓名不能为空
|
|
|
+ break
|
|
|
+ }
|
|
|
+ basestation := new(AnimalInfo)
|
|
|
+ for cellindex, cell := range row.Cells { //循环列数
|
|
|
+ if cell.String() != "" {
|
|
|
+ if cellindex == 0 {
|
|
|
+ basestation.ProvinceName = cell.String()
|
|
|
+ } else if cellindex == 1 {
|
|
|
+ if cell.String() == "" {
|
|
|
+ basestation.Name = "其他"
|
|
|
+ basestation.Genus = "其他"
|
|
|
+ } else {
|
|
|
+ basestation.Name = cell.String()
|
|
|
+ basestation.Genus = cell.String()
|
|
|
+ }
|
|
|
+ } else if cellindex == 2 {
|
|
|
+ basestation.CityName = cell.String()
|
|
|
+ } else if cellindex == 3 {
|
|
|
+ basestation.StreetName = cell.String()
|
|
|
+ } else if cellindex == 4 {
|
|
|
+ basestation.Address = cell.String()
|
|
|
+ } else if cellindex == 5 {
|
|
|
+ aa, _ := utils.StrTo(cell.Value).Float64()
|
|
|
+ basestation.SurveyDate = xlsx.TimeFromExcelTime(aa, false)
|
|
|
+ } else if cellindex == 6 {
|
|
|
+ basestation.InnerNo = cell.String()
|
|
|
+ } else if cellindex == 7 {
|
|
|
+ basestation.Amount, _ = utils.StrTo(cell.String()).Int()
|
|
|
+ } else if cellindex == 8 {
|
|
|
+ basestation.Longitude = cell.String()
|
|
|
+ } else if cellindex == 9 {
|
|
|
+ basestation.Latitude = cell.String()
|
|
|
+ } else if cellindex == 10 {
|
|
|
+ basestation.Altitude = cell.String()
|
|
|
+ } else if cellindex == 11 {
|
|
|
+ basestation.AreaCode = cell.String()
|
|
|
+ } else if cellindex == 12 {
|
|
|
+ basestation.Province = cell.String()
|
|
|
+ } else if cellindex == 13 {
|
|
|
+ basestation.City = cell.String()
|
|
|
+ } else if cellindex == 14 {
|
|
|
+ basestation.Street = cell.String()
|
|
|
+ } else if cellindex == 15 {
|
|
|
+ basestation.ZBack17 = cell.String()
|
|
|
+ } else if cellindex == 16 {
|
|
|
+ basestation.ZBack11 = cell.String()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ basestation.AccCode = accode
|
|
|
+ basestation.Unit = "群"
|
|
|
+ basestation.ProjectId = 0
|
|
|
+ basestation.ProjectName = "技术体系"
|
|
|
+ basestation.CreateOn = time.Now()
|
|
|
+ basestation.CreateBy = createby
|
|
|
+ basestation.CreateUserId = createuserid
|
|
|
|
|
|
-// basestation.IsInformed = 0
|
|
|
-// basestation.XPublicState = 0
|
|
|
-// basestation.AccCode = accode
|
|
|
-// basestation.CreateOn = time.Now()
|
|
|
-// basestation.CreateBy = createby
|
|
|
-// basestation.CreateUserId = createuserid
|
|
|
+ sqlfield := "AccCode,Genus,InnerNo,Name,Amount,Unit,Province,ProvinceName,City,CityName,"
|
|
|
+ sqlfield = sqlfield + "Street,StreetName,Address,AreaCode,Longitude,Latitude,Altitude,SurveyDate"
|
|
|
+ sqlfield = sqlfield + "ProjectId,ProjectName,"
|
|
|
+ sqlfield = sqlfield + "CreateUserId,CreateBy,CreateOn"
|
|
|
+ sqlfield = sqlfield + notefieldstr
|
|
|
|
|
|
-// whereposition := " (IdCard = '" + basestation.IdCard + "' and Name ='" + basestation.Name + "') "
|
|
|
-// whereposition = whereposition + " or (Name='" + basestation.Name + "' and Telephone ='" + basestation.Telephone + "')"
|
|
|
-// have := s.QueryDonorshas(tablename, whereposition)
|
|
|
-// if have {
|
|
|
-// continue
|
|
|
-// }
|
|
|
-// sqlfield := "AccCode,IdCard,Name,Sex,CompanyName,Duty,Birthday,Age,Mobile,Telephone,Email,"
|
|
|
-// sqlfield = sqlfield + "Nation,ComeFrom,HomeAddress,MaritalStatus,XISNum,AdmissionNumber,"
|
|
|
-// sqlfield = sqlfield + "IsInformed,PathologicalNum,ClinicalDiagnosis,ClinicNum,CheckNum,CheckPoint,"
|
|
|
-// sqlfield = sqlfield + "IllnessName,XPublicState,CreateUserId,CreateBy,Department,DiagnosticTime,CreateOn,ModifiedOn,InnerNo"
|
|
|
-// sqlfield = sqlfield + notefieldstr
|
|
|
+ sqlvalue := "'" + basestation.AccCode + "','" + basestation.Genus + "','" + basestation.InnerNo + "','" + basestation.Name + "'," + utils.ToStr(basestation.Amount) + ",'" + basestation.Unit + "',"
|
|
|
+ sqlvalue = sqlvalue + "'" + basestation.Province + "','" + basestation.ProvinceName + "','" + basestation.City + "','" + basestation.CityName + "','"+ basestation.Street + "',"
|
|
|
+ sqlvalue = sqlvalue + "'" + basestation.StreetName + "','" + basestation.Address + "','" + basestation.AreaCode + "','" + basestation.Longitude + "','" + basestation.Latitude + "',"
|
|
|
+ sqlvalue = sqlvalue + "'" + basestation.Altitude + "','" + basestation.SurveyDate.Format("2006-1-2 15:4:5") + "'," + utils.ToStr(basestation.ProjectId) + ",'" + basestation.ProjectName + "',"
|
|
|
+ sqlvalue = sqlvalue + "" + utils.ToStr(basestation.CreateUserId) + ",'" + basestation.CreateBy + "','" + "now(),now()'"
|
|
|
+ sqlvalue = sqlvalue + notevaluestr
|
|
|
+ s.AddLine(tablename, sqlfield, sqlvalue)
|
|
|
|
|
|
-// sqlvalue := "'" + basestation.AccCode + "','" + basestation.IdCard + "','" + basestation.Name + "'," + utils.ToStr(basestation.Sex) + ",'" + basestation.CompanyName + "',"
|
|
|
-// sqlvalue = sqlvalue + "'" + basestation.Duty + "','" + basestation.Birthday.Format("2006-1-2 15:4:5") + "'," + utils.ToStr(basestation.Age) + ",'" + basestation.Mobile + "','" + basestation.Telephone + "',"
|
|
|
-// sqlvalue = sqlvalue + "'" + basestation.Email + "','" + basestation.Nation + "','" + basestation.ComeFrom + "','" + basestation.HomeAddress + "'," + utils.ToStr(basestation.MaritalStatus) + ","
|
|
|
-// sqlvalue = sqlvalue + "'" + basestation.XISNum + "','" + basestation.AdmissionNumber + "'," + utils.ToStr(basestation.IsInformed) + ",'" + basestation.PathologicalNum + "','" + basestation.ClinicalDiagnosis + "',"
|
|
|
-// sqlvalue = sqlvalue + "'" + basestation.ClinicNum + "'," + utils.ToStr(basestation.CheckNum) + ",'" + basestation.CheckPoint + "','" + basestation.IllnessName + "'," + utils.ToStr(basestation.XPublicState) + ","
|
|
|
-// sqlvalue = sqlvalue + "" + utils.ToStr(basestation.CreateUserId) + ",'" + basestation.CreateBy + "','" + basestation.Department + "','" + basestation.DiagnosticTime.Format("2006-1-2 15:4:5") + "',now(),now(),'" + basestation.InnerNo + "'"
|
|
|
-// sqlvalue = sqlvalue + notevaluestr
|
|
|
-// s.AddLine(tablename, sqlfield, sqlvalue)
|
|
|
+ if rowindex == (sheetrows) {
|
|
|
+ s.AddLine(tablename, sqlfield, sqlvalue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return err, warn1
|
|
|
+}
|
|
|
|
|
|
-// if rowindex == (sheetrows) {
|
|
|
-// s.AddLine(tablename, sqlfield, sqlvalue)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return err, warn1
|
|
|
-//}
|
|
|
+//数据写入数据库
|
|
|
+func (s *SamplesSourceService) AddLine(tableName, fieldName, fieldValue string) error {
|
|
|
+ sql := "insert into " + tableName + "(" + fieldName + ") values(" + fieldValue + ")"
|
|
|
+ fmt.Println(sql)
|
|
|
+ _, err := s.DBE.Exec(sql)
|
|
|
+ return err
|
|
|
+}
|