4
0
Преглед на файлове

蜜蜂所样本来源导入

shihang преди 6 години
родител
ревизия
d1f67cf29e

+ 62 - 15
src/dashoo.cn/backend/api/business/samplessource/samplessourceService.go

@@ -2,13 +2,16 @@ package samplessource
 
 import (
 	"fmt"
-	"github.com/tealeg/xlsx"
 	"os"
+
 	"time"
 
+	"github.com/tealeg/xlsx"
+
 	//"fmt"
 	"strconv"
 
+	"dashoo.cn/backend/api/business/codecsequence"
 	. "dashoo.cn/backend/api/mydb"
 	"dashoo.cn/utils"
 	. "dashoo.cn/utils/db"
@@ -77,12 +80,11 @@ func (s *SamplesSourceService) InsertExcelAnimal(excelpath, tablename, accode, c
 	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 := ""
+			//notefieldstr := ""
+			//notevaluestr := ""
 			if rowindex == 0 {
 				continue
 			}
@@ -146,21 +148,23 @@ func (s *SamplesSourceService) InsertExcelAnimal(excelpath, tablename, accode, c
 			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 + "Street,StreetName,Address,AreaCode,Longitude,Latitude,Altitude,SurveyDate,"
 			sqlfield = sqlfield + "ProjectId,ProjectName,"
-			sqlfield = sqlfield + "CreateUserId,CreateBy,CreateOn"
-			sqlfield = sqlfield + notefieldstr
+			sqlfield = sqlfield + "CreateUserId,CreateBy,CreateOn,"
+			sqlfield = sqlfield + "ZBack11,ZBack17"
+			//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.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 = sqlvalue + "" + utils.ToStr(basestation.CreateUserId) + ",'" + basestation.CreateBy + "'," + "now(),"
+			sqlvalue = sqlvalue + "'" + basestation.ZBack11 + "','" + basestation.ZBack17 + "'"
+			//sqlvalue = sqlvalue + notevaluestr
+			s.AddLine(tablename, sqlfield, sqlvalue, basestation.InnerNo)
 
 			if rowindex == (sheetrows) {
-				s.AddLine(tablename, sqlfield, sqlvalue)
+				s.AddLine(tablename, sqlfield, sqlvalue, basestation.InnerNo)
 			}
 		}
 	}
@@ -168,9 +172,52 @@ func (s *SamplesSourceService) InsertExcelAnimal(excelpath, tablename, accode, c
 }
 
 //数据写入数据库
-func (s *SamplesSourceService) AddLine(tableName, fieldName, fieldValue string) error {
-	sql := "insert into " + tableName + "(" + fieldName + ") values(" + fieldValue + ")"
+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 + "'"
+	s.DBE.Table(tablename).Where(where).Get(&model)
+
+	entityname := "CodecSequence"
+	var list []codecsequence.CodecSequence
+	where_seq := "AccCode = '" + model.AccCode + "'"
+	where_seq += " and AreaCode = '" + model.AreaCode + "'"
+	s.DBE.Table(entityname).Where(where_seq).Find(&list)
+
+	if len(list) == 0 {
+		var entity codecsequence.CodecSequence
+		entity.AccCode = model.AccCode
+		entity.SeqName = strconv.Itoa(model.Id)
+		entity.AreaCode = model.AreaCode
+		entity.MinValue = 1
+		entity.MaxValue = model.Amount
+		entity.CurrentVal = 1
+		entity.IncrementVal = 1
+		entity.CreateBy = model.CreateBy
+		entity.CreateUserId = model.CreateUserId
+		_, err := s.DBE.Table(entityname).Insert(entity)
+		return err
+	} else {
+		var entity codecsequence.CodecSequence
+		entity.AccCode = model.AccCode
+		entity.SeqName = strconv.Itoa(model.Id)
+		entity.AreaCode = model.AreaCode
+		entity.MinValue = list[len(list)-1].MaxValue + 1
+		entity.MaxValue = list[len(list)-1].MaxValue + model.Amount
+		entity.CurrentVal = list[len(list)-1].MaxValue + 1
+		entity.IncrementVal = 1
+		entity.CreateBy = model.CreateBy
+		entity.CreateUserId = model.CreateUserId
+		_, err := s.DBE.Table(entityname).Insert(entity)
+		return err
+	}
+}

+ 14 - 45
src/dashoo.cn/backend/api/controllers/biobank/samplessource.go

@@ -1409,51 +1409,20 @@ func (this *SamplesSourceController) DaySaveXlsxExport(name string, title []stri
 // @Success	200	{object} controllers.Request
 // @router /exceltosave [put]
 func (this *SamplesSourceController) SaveExcelPost() {
-	tablename := this.User.AccCode + AnimaltbName
+	path := this.GetString("path")
 	svc := samplessource.GetSamplesSourceService(utils.DBE)
-	var model samplessource.AnimalInfo
 	uid, _ := utils.StrTo(this.User.Id).Int()
-	err, warn1 := svc.InsertExcelAnimal(this.GetString("path"), tablename, this.User.AccCode, this.User.Realname, uid)
-		var errinfo ErrorInfo
-		if warn1 == "" {
-			errinfo.Message = "样本来源数据导入成功!"
-			errinfo.Code = 0
-		}
-		if err != nil {
-			errinfo.Message = "样本来源数据导入失败!"
-			errinfo.Code = -1
-		}
-		this.Data["json"] = &errinfo
-		this.ServeJSON()
-		return
-
-
-	var list []codecsequence.CodecSequence
-		where_seq := "AccCode = '" + this.User.AccCode + "'"
-		where_seq += " and AreaCode = '" + model.AreaCode + "'"
-		svc.GetEntitysByWhere(CodecSequenceName, where_seq, &list)
-		var entity codecsequence.CodecSequence
-		if len(list) == 0 {
-			entity.AccCode = this.User.AccCode
-			//entity.SeqName = strconv.Itoa(model.Id)
-			entity.AreaCode = model.AreaCode
-			//entity.MinValue = 1
-			//entity.MaxValue = model.Amount
-			//entity.CurrentVal = 1
-			//entity.IncrementVal = 1
-			entity.CreateBy = this.User.Realname
-			entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
-			svc.InsertEntity(&entity)
-		} else {
-			entity.AccCode = this.User.AccCode
-			//entity.SeqName = strconv.Itoa(model.Id)
-			entity.AreaCode = model.AreaCode
-			//entity.MinValue = list[len(list)-1].MaxValue + 1
-			//entity.MaxValue = list[len(list)-1].MaxValue + model.Amount
-			//entity.CurrentVal = list[len(list)-1].MaxValue + 1
-			//entity.IncrementVal = 1
-			entity.CreateBy = this.User.Realname
-			entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
-			svc.InsertEntity(&entity)
-		}
+	err, warn1 := svc.InsertExcelAnimal(path, this.User.AccCode+AnimaltbName, this.User.AccCode, this.User.Realname, uid)
+	var errinfo ErrorInfo
+	if warn1 == "" {
+		errinfo.Message = "样本来源数据导入成功!"
+		errinfo.Code = 0
+	}
+	if err != nil {
+		errinfo.Message = "样本来源数据导入失败!"
+		errinfo.Code = -1
+	}
+	this.Data["json"] = &errinfo
+	this.ServeJSON()
+	return
 }

+ 0 - 2
src/dashoo.cn/backend/api/mydb/myServiceBase.go

@@ -91,8 +91,6 @@ func (s *MyServiceBase) GetEntityByWhere(tablename string, where string, entityP
 
 func (s *MyServiceBase) GetEntityByWhereBytbl(tablename, where string, entityPtr interface{}) {
 	s.DBE.Table(tablename).Where(where).Get(entityPtr)
-
-	//	s.DBE.Sql(sql).Get(&entity)
 	return
 }
 

+ 1 - 6
src/dashoo.cn/frontend_animal/src/pages/biobank/source/_opera/operationb.vue

@@ -24,7 +24,7 @@
         <span style="float: right;">
 
           <!--审核模块 暂未进行任何修改版本-->
-          <el-button type="primary" size="mini" style="margin-left:10px; margin-top: -4px;" @click="auditorshow"
+          <el-button type="primary" size="mini" style="margin-left:10px; margin-top: -4px;" @click="auditorShow = true"
             v-if="permissions[permissionscode.srapprove] && service_flag == 'editsource'"
             :disabled="samplesForm.AuditorStatus != 0 || !author_flag">审核</el-button>
           <!--审核模块结束-->
@@ -517,11 +517,6 @@
           }
         })
       },
-      // 打开审核弹窗
-      auditorshow() {
-        let _this = this
-        _this.auditorShow = true
-      },
       auditor() {
         let _this = this
         _this.$confirm("确定审核该样本来源?审核后所有信息将不可修改!", "提示", {

+ 1 - 3
src/dashoo.cn/frontend_animal/src/pages/biobank/source/animal.vue

@@ -341,9 +341,7 @@
           })
           return
         }
-        _this.$axios.put('/samplessource/exceltosave', {
-          URL: this.importfilepath
-        })
+        _this.$axios.put('/samplessource/exceltosave?path=' + this.importfilepath, {})
           .then(res => {
             if (res.data.code === 0) {
               _this.$message({