|
|
@@ -12,6 +12,7 @@ import (
|
|
|
"strconv"
|
|
|
|
|
|
"dashoo.cn/backend/api/business/codecsequence"
|
|
|
+ "dashoo.cn/backend/api/business/extend"
|
|
|
. "dashoo.cn/backend/api/mydb"
|
|
|
"dashoo.cn/utils"
|
|
|
. "dashoo.cn/utils/db"
|
|
|
@@ -171,17 +172,6 @@ func (s *SamplesSourceService) InsertExcelAnimal(excelpath, tablename, accode, c
|
|
|
return err, warn1
|
|
|
}
|
|
|
|
|
|
-//数据写入数据库
|
|
|
-func (s *SamplesSourceService) AddLine(tablename, fieldName, fieldValue, innerno string) error {
|
|
|
- sql := "insert into " + tablename + "(" + fieldName + ") values(" + fieldValue + ")"
|
|
|
- fmt.Println(sql)
|
|
|
- _, err := s.DBE.Exec(sql)
|
|
|
-
|
|
|
- s.AddCodes(tablename, innerno)
|
|
|
-
|
|
|
- return err
|
|
|
-}
|
|
|
-
|
|
|
func (s *SamplesSourceService) AddCodes(tablename, innerno string) error {
|
|
|
var model AnimalInfo
|
|
|
where := "InnerNo = '" + innerno + "'"
|
|
|
@@ -221,3 +211,176 @@ func (s *SamplesSourceService) AddCodes(tablename, innerno string) error {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+//数据写入数据库
|
|
|
+func (s *SamplesSourceService) AddLine(tablename, fieldName, fieldValue, innerno string) error {
|
|
|
+ sql := "insert into " + tablename + "(" + fieldName + ") values(" + fieldValue + ")"
|
|
|
+ fmt.Println(sql)
|
|
|
+ _, err := s.DBE.Exec(sql)
|
|
|
+ s.AddCodes(tablename, innerno)
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+//样本源导入--人
|
|
|
+func (s *SamplesSourceService) InsertExcelSource(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
|
|
|
+ }
|
|
|
+
|
|
|
+ basestation.IsInformed = 0
|
|
|
+ basestation.XPublicState = 0
|
|
|
+ basestation.AccCode = accode
|
|
|
+ basestation.CreateOn = time.Now()
|
|
|
+ basestation.CreateBy = createby
|
|
|
+ basestation.CreateUserId = createuserid
|
|
|
+
|
|
|
+ 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.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.AddSourceLine(tablename, sqlfield, sqlvalue)
|
|
|
+
|
|
|
+ if rowindex == (sheetrows) {
|
|
|
+ s.AddSourceLine(tablename, sqlfield, sqlvalue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return err, warn1
|
|
|
+}
|
|
|
+
|
|
|
+func (s *SamplesSourceService) AddSourceLine(tablename, fieldName, fieldValue string) error {
|
|
|
+ sql := "insert into " + tablename + "(" + fieldName + ") values(" + fieldValue + ")"
|
|
|
+ fmt.Println(sql)
|
|
|
+ _, err := s.DBE.Exec(sql)
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+//判断是否存在此样本来源
|
|
|
+func (s *SamplesSourceService) QueryDonorshas(tablename, where string) bool {
|
|
|
+ var num MyInt_Id
|
|
|
+ sql := "select Id from " + tablename
|
|
|
+ if where != "" {
|
|
|
+ sql = sql + " where " + where + " limit 1 "
|
|
|
+ }
|
|
|
+ s.DBE.Sql(sql).Get(&num)
|
|
|
+ total := num.Id
|
|
|
+ if total > 0 {
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+}
|