4
0
shiyi 6 лет назад
Родитель
Сommit
6235579e48

+ 107 - 135
src/dashoo.cn/backend/api/business/samplessource/samplessourceService.go

@@ -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
+}

+ 1 - 1
src/dashoo.cn/backend/api/controllers/base.go

@@ -254,7 +254,7 @@ func (this *BaseController) Prepare() {
 		"/api/webinterface/preparelist", "/api/webinterface/prepareinfo",
 		"/api/sampletest_v/sampletest", "/api/sampletest_v/getpass", "/api/sampletest_v/editpass/",
 		"/api/sampletest_v/donorsdetail", "/api/sampletest_v/testdetail", "/api/uploads/samplesinput", "/api/doctemplate_onlyoffice/callback", "/api/doctemplate_onlyoffice/viewcallback", "/api/limsupload/usersignimg",
-		"/api/uploads/samplestypeimg", "/api/limsdataentry/historyimg/"}
+		"/api/uploads/samplestypeimg", "/api/limsdataentry/historyimg/", "/api/uploads/exportanimal"}
 	for _, v := range urls {
 		fmt.Println("**this.Ctx.Input.URL()**", this.Ctx.Input.URL())
 		if this.Ctx.Input.URL() == v {

+ 47 - 16
src/dashoo.cn/backend/api/controllers/biobank/samplessource.go

@@ -1331,20 +1331,51 @@ func (this *SamplesSourceController) DaySaveXlsxExport(name string, title []stri
 // @Success	200	{object} controllers.Request
 // @router /exceltosave [put]
 func (this *SamplesSourceController) SaveExcelPost() {
-	//	tablename := this.User.AccCode + DonorstbName
-	//	svc := donorsinfo.GetDonorsInfoService(utils.DBE)
-	//	uid, _ := utils.StrTo(this.User.Id).Int()
-	//	err, warn1 := svc.InsertExcelDonors(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
+	tablename := this.User.AccCode + AnimaltbName
+	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)
+		}
 }

+ 11 - 0
src/dashoo.cn/backend/api/controllers/upload.go

@@ -60,6 +60,17 @@ func (this *UploadController) Exportdonors() {
 	this.ServeJSON()
 }
 
+// @Title 上传动物样本来源
+// @Description 上传动物样本来源
+// @Success 200 {object} business.device.DeviceChannels
+// @router /exportanimal [post]
+func (this *UploadController) ExportAnimal() {
+	accode := this.GetString("accode")
+	excelpath := UploadFile("animal.xlsx", "/static/upload/excel/export/"+accode+"/", this.Ctx.Request, "file")
+	this.Data["json"] = excelpath
+	this.ServeJSON()
+}
+
 // @Title 申请单样本导入
 // @Description 报警项目列表
 // @Success 200 {object} business.device.DeviceChannels

BIN
src/dashoo.cn/backend/api/static/upload/excel/export/sgVEw/2019/5/animal.xlsx


+ 3 - 2
src/dashoo.cn/frontend_animal/nuxt.config.js

@@ -14,7 +14,7 @@ module.exports = {
    ** Headers of the page
    */
   head: {
-    title: '样本库系统', 
+    title: '样本库系统',
     meta: [{
         charset: 'utf-8'
       },
@@ -175,7 +175,8 @@ module.exports = {
   env: {
     appclient: 'biobank', //因顿LIMS:lims,样本库:biobank,细胞制备:cellbank,样本搜索判断,登录跳转判断
 
-    imgserverhost: 'http://47.92.238.200:9081', // BioBank服务地址,图片上传文件
+    // imgserverhost: 'http://47.92.238.200:9081', // BioBank服务地址,图片上传文件
+    imgserverhost: 'http://localhost:9081', // BioBank服务地址,图片上传文件
     upfilehost: 'http://weed1.labsop.cn:9333/dir/assign', // 附件上传
 
     //imgserverhost: 'http://188.188.30.89:9081', // 临沂服务地址,图片上传文件

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

@@ -13,6 +13,7 @@
           <router-link :to="'/biobank/source/addsource/operationb'">
             <el-button type="primary" size="mini" style="margin-left:10px; margin-top: -4px;">添加</el-button>
           </router-link>
+          <el-button size="mini" type="primary" style="margin-left:10px; margin-top: -4px;" @click="importVisible = true">导入</el-button>
         </span>
         <el-form ref="form" :inline="true" style="float: right; margin-top: -10px">
           <el-form-item label="样本源名称">
@@ -87,7 +88,6 @@
         :total="currentItemCount">
       </el-pagination>
     </el-card>
-
     <el-dialog title="高级查询" :visible.sync="dialogVisible" width="700px">
       <el-form ref="advancedSearchForm" label-width="90px">
         <el-row>
@@ -166,6 +166,18 @@
         <el-button size="mini" type="primary" @click="seachdata">查 询</el-button>
       </span>
     </el-dialog>
+
+    <el-dialog title="样本批量导入" :visible.sync="importVisible">
+      <el-upload :action="filehost + '/api/uploads/exportanimal'" :show-file-list="false" :data="importfileparam"
+                 :on-success="handleexportfileSuccess" :before-upload="beforeexportfileUpload">
+        <el-button size="mini" type="primary">点击上传导入文件</el-button> <span>{{importmsg}}</span>
+        <div slot="tip" class="el-upload__tip">只能上传由导入模板录入的xlsx文件,其中模板中带星号(*)的为必填项,不填写将会被忽略</div>
+      </el-upload>
+      <div slot="footer">
+        <el-button type="primary" @click="importData()" size="mini">确定</el-button>
+        <el-button @click="importVisible = false" size="mini">取消</el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 <script>
@@ -182,6 +194,11 @@
     name: 'samplessource',
     data() {
       return {
+        filehost: '',
+        importfileparam: {}, // 导入文件参数
+        importfilepath: '', //导入文件路径
+        importVisible: false, // 导入对话框
+        importmsg: '未选择文件', // 导入文件
         dialogVisible: false,
         classificationlist: [],
         searchform: {
@@ -218,9 +235,13 @@
       }
     },
     created() {
+      this.filehost = process.env.imgserverhost
       this.initdata()
       this.getAnimalGenus()
       this.getProjectlist()
+      this.importfileparam = {
+        accode: this.authUser.Profile.AccCode
+      }
     },
     methods: {
       initdata() {
@@ -310,6 +331,64 @@
             .catch(() => {})
         }).catch(() => {})
       },
+      //导入蜜蜂样本来源
+      importData() {
+        let _this = this
+        if (_this.importfilepath === '') {
+          _this.$message({
+            type: 'warning',
+            message: '请先上传导入文件!'
+          })
+          return
+        }
+        _this.$axios.put('/samplessource/exceltosave', {
+          URL: this.importfilepath
+        })
+          .then(res => {
+            if (res.data.code === 0) {
+              _this.$message({
+                type: 'success',
+                message: res.data.message
+              })
+              _this.importVisible = false
+              _this.importfilepath = ''
+              _this.importmsg = '未选择文件'
+              // 更新界面
+              _this.initData()
+            } else {
+              _this.$message({
+                type: 'warning',
+                message: res.data.message
+              })
+            }
+          })
+          .catch(err => {
+            console.error(err)
+          })
+      },
+      handleexportfileSuccess(res, file) {
+        this.importfilepath = res
+      },
+      beforeexportfileUpload(file) {
+        let i = file.name.lastIndexOf('.')
+        let typename = ''
+        if (i > -1) {
+          typename = file.name.substring(i)
+        }
+        let istype = (typename === '.xlsx')
+        let isLt50k = file.size / 1024 / 1024 / 2 < 1
+        if (!istype) {
+          this.$message.error('上传导入文件只能是 xlsx 格式!')
+          return false
+        }
+        if (!isLt50k) {
+          this.$message.error('上传导入文件大小不能超过 2M!')
+          return false
+        }
+        this.importmsg = '上传文件:' + file.name
+        return true
+      },
+
       //列表排序功能
       orderby(column) {
         if (column.order == 'ascending') {