ソースを参照

设备台账导出

lining 6 年 前
コミット
515e92b5ee

+ 114 - 29
src/dashoo.cn/backend/api/controllers/lims/limscheckequipmentlist.go

@@ -4,8 +4,9 @@ import (
 	"dashoo.cn/backend/api/business/limscustomerposition"
 	"dashoo.cn/backend/api/business/organize"
 	"encoding/json"
+	"github.com/tealeg/xlsx"
 	"strconv"
-
+	"strings"
 	//"strings"
 	"time"
 
@@ -56,7 +57,7 @@ func (this *LimsCheckEquipmentListController) GetEntityList() {
 	TemplateTypeId := this.GetString("TemplateTypeId")
 	PositionAllTypeId := this.GetString("PositionAllTypeId")
 	QueryCheckDate := this.GetString("QueryCheckDate")
-	statusValue:=this.GetString("statusValue")
+	statusValue := this.GetString("statusValue")
 
 	if Id != "" {
 		where = where + " and Id like '%" + Id + "%'"
@@ -118,12 +119,12 @@ func (this *LimsCheckEquipmentListController) GetEntityList() {
 		where = where + " and  date_add(LastCheckDate, interval " + QueryCheckDate + " month) >= now()"
 	}
 
-	if statusValue!=""{
-		if statusValue=="-2"{
+	if statusValue != "" {
+		if statusValue == "-2" {
 			where = where + " and  NextCheckDate < DATE_FORMAT(NOW(),'%Y-%m-%d') "
-		}else if statusValue=="-1"{
+		} else if statusValue == "-1" {
 			where = where + " and  NextCheckDate >= DATE_FORMAT(NOW(),'%Y-%m-%d') and NextCheckDate <= DATE_FORMAT(date_add(NOW(), interval 1 month),'%Y-%m-%d') "
-		}else{
+		} else {
 			where = where + " and  NextCheckDate > DATE_FORMAT(date_add(NOW(), interval 1 month),'%Y-%m-%d') "
 		}
 	}
@@ -133,7 +134,7 @@ func (this *LimsCheckEquipmentListController) GetEntityList() {
 	positionSvc := limscustomerposition.GetLimsCustomerpositionService(utils.DBE)
 	if this.User.UintThirdId > 0 {
 		var entitys []limscustomerposition.LimsCustomerPosition
-		entitys = positionSvc.GetPositionCheckList( this.User.AccCode + LimsCustomerpositionName, strconv.Itoa(this.User.UintThirdId) )
+		entitys = positionSvc.GetPositionCheckList(this.User.AccCode+LimsCustomerpositionName, strconv.Itoa(this.User.UintThirdId))
 		for _, value := range entitys {
 			strPositionList += strconv.Itoa(value.Id) + ","
 		}
@@ -147,7 +148,7 @@ func (this *LimsCheckEquipmentListController) GetEntityList() {
 		}
 		thrOrgList += "0"
 		var entitys []limscustomerposition.LimsCustomerPosition
-		entitys = positionSvc.GetPositionCheckList( this.User.AccCode + LimsCustomerpositionName, thrOrgList )
+		entitys = positionSvc.GetPositionCheckList(this.User.AccCode+LimsCustomerpositionName, thrOrgList)
 		for _, value := range entitys {
 			strPositionList += strconv.Itoa(value.Id) + ","
 		}
@@ -230,14 +231,14 @@ func (this *LimsCheckEquipmentListController) AddEntity() {
 	model.Departmentname = organizeEntity.Fullname
 
 	//计算下次检测日期
-	if model.CycleUnit=="天"{
-		model.NextCheckDate=model.LastCheckDate.AddDate(0,0,int(model.Cycle))
-	}else if  model.CycleUnit=="月"{
-		model.NextCheckDate=model.LastCheckDate.AddDate(0,int(model.Cycle),0)
-	}else if  model.CycleUnit=="年"{
-		model.NextCheckDate=model.LastCheckDate.AddDate(int(model.Cycle),0,0)
-	}else{
-		model.NextCheckDate=model.LastCheckDate
+	if model.CycleUnit == "天" {
+		model.NextCheckDate = model.LastCheckDate.AddDate(0, 0, int(model.Cycle))
+	} else if model.CycleUnit == "月" {
+		model.NextCheckDate = model.LastCheckDate.AddDate(0, int(model.Cycle), 0)
+	} else if model.CycleUnit == "年" {
+		model.NextCheckDate = model.LastCheckDate.AddDate(int(model.Cycle), 0, 0)
+	} else {
+		model.NextCheckDate = model.LastCheckDate
 	}
 	_, err := svc.InsertEntityBytbl(this.User.AccCode+LimsCheckEquipmentListName, &model)
 
@@ -283,14 +284,14 @@ func (this *LimsCheckEquipmentListController) UpdateEntity() {
 	model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
 
 	//计算下次检测日期
-	if model.CycleUnit=="天"{
-		model.NextCheckDate=model.LastCheckDate.AddDate(0,0,int(model.Cycle))
-	}else if  model.CycleUnit=="月"{
-		model.NextCheckDate=model.LastCheckDate.AddDate(0,int(model.Cycle),0)
-	}else if  model.CycleUnit=="年"{
-		model.NextCheckDate=model.LastCheckDate.AddDate(int(model.Cycle),0,0)
-	}else{
-		model.NextCheckDate=model.LastCheckDate
+	if model.CycleUnit == "天" {
+		model.NextCheckDate = model.LastCheckDate.AddDate(0, 0, int(model.Cycle))
+	} else if model.CycleUnit == "月" {
+		model.NextCheckDate = model.LastCheckDate.AddDate(0, int(model.Cycle), 0)
+	} else if model.CycleUnit == "年" {
+		model.NextCheckDate = model.LastCheckDate.AddDate(int(model.Cycle), 0, 0)
+	} else {
+		model.NextCheckDate = model.LastCheckDate
 	}
 
 	cols := []string{
@@ -491,7 +492,7 @@ func (this *LimsCheckEquipmentListController) GetEntityWarningList() {
 	positionSvc := limscustomerposition.GetLimsCustomerpositionService(utils.DBE)
 	if this.User.UintThirdId > 0 {
 		var entitys []limscustomerposition.LimsCustomerPosition
-		entitys = positionSvc.GetPositionCheckList( this.User.AccCode + LimsCustomerpositionName, strconv.Itoa(this.User.UintThirdId) )
+		entitys = positionSvc.GetPositionCheckList(this.User.AccCode+LimsCustomerpositionName, strconv.Itoa(this.User.UintThirdId))
 		for _, value := range entitys {
 			strPositionList += strconv.Itoa(value.Id) + ","
 		}
@@ -505,7 +506,7 @@ func (this *LimsCheckEquipmentListController) GetEntityWarningList() {
 		}
 		thrOrgList += "0"
 		var entitys []limscustomerposition.LimsCustomerPosition
-		entitys = positionSvc.GetPositionCheckList( this.User.AccCode + LimsCustomerpositionName, thrOrgList )
+		entitys = positionSvc.GetPositionCheckList(this.User.AccCode+LimsCustomerpositionName, thrOrgList)
 		for _, value := range entitys {
 			strPositionList += strconv.Itoa(value.Id) + ","
 		}
@@ -520,8 +521,8 @@ func (this *LimsCheckEquipmentListController) GetEntityWarningList() {
 	var list []limscheckequipmentlist.LimsCheckEquipmentList
 
 	where = where + " and CASE WHEN CycleUnit ='年' THEN DATE_ADD(LastCheckDate , INTERVAL Cycle YEAR) < NOW() || DATE_ADD(LastCheckDate , INTERVAL Cycle YEAR) < DATE_ADD(NOW(),INTERVAL 1 MONTH) " +
-		           "WHEN CycleUnit ='月' THEN DATE_ADD(LastCheckDate , INTERVAL Cycle MONTH) < NOW() || DATE_ADD(LastCheckDate , INTERVAL Cycle MONTH) < DATE_ADD(NOW(),INTERVAL 1 MONTH)" +
-					"WHEN CycleUnit ='天' THEN DATE_ADD(LastCheckDate , INTERVAL Cycle DAY) < NOW() || DATE_ADD(LastCheckDate , INTERVAL Cycle DAY) < DATE_ADD(NOW(),INTERVAL 1 MONTH) ELSE FALSE END"
+		"WHEN CycleUnit ='月' THEN DATE_ADD(LastCheckDate , INTERVAL Cycle MONTH) < NOW() || DATE_ADD(LastCheckDate , INTERVAL Cycle MONTH) < DATE_ADD(NOW(),INTERVAL 1 MONTH)" +
+		"WHEN CycleUnit ='天' THEN DATE_ADD(LastCheckDate , INTERVAL Cycle DAY) < NOW() || DATE_ADD(LastCheckDate , INTERVAL Cycle DAY) < DATE_ADD(NOW(),INTERVAL 1 MONTH) ELSE FALSE END"
 	total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
 	var datainfo DataInfo
 	datainfo.Items = list
@@ -530,4 +531,88 @@ func (this *LimsCheckEquipmentListController) GetEntityWarningList() {
 	datainfo.ItemsPerPage = page.Size
 	this.Data["json"] = &datainfo
 	this.ServeJSON()
-}
+}
+
+// @Title get 导出ex
+// @Description get SampleType by token
+// @Success 200 {object}
+// @router /exportexcelall [get]
+func (this *LimsCheckEquipmentListController) ExportExcelAll() {
+	//获取分页信息
+	//page := this.GetPageInfoForm()
+	where := " 1=1 "
+
+	PositionAllTypeId := this.GetString("PositionAllTypeId")
+	if PositionAllTypeId != "" {
+		where = where + " and (PositionCheckId = '" + PositionAllTypeId + "' or PositionID = '" + PositionAllTypeId + "')"
+	}
+
+
+	strPositionList := ""
+	orgSvc := organize.GetOrganizeService(utils.DBE)
+	positionSvc := limscustomerposition.GetLimsCustomerpositionService(utils.DBE)
+	if this.User.UintThirdId > 0 {
+		var entitys []limscustomerposition.LimsCustomerPosition
+		entitys = positionSvc.GetPositionCheckList(this.User.AccCode+LimsCustomerpositionName, strconv.Itoa(this.User.UintThirdId))
+		for _, value := range entitys {
+			strPositionList += strconv.Itoa(value.Id) + ","
+		}
+		strPositionList += "0"
+	} else if this.User.UnitId > 0 {
+		orgEntityList := orgSvc.GetAllThirdChildByTopId(strconv.Itoa(this.User.UnitId), this.User.Id)
+		//取消3级单位ID列表
+		thrOrgList := ""
+		for _, orgValue := range orgEntityList {
+			thrOrgList += strconv.Itoa(orgValue.Id) + ","
+		}
+		thrOrgList += "0"
+		var entitys []limscustomerposition.LimsCustomerPosition
+		entitys = positionSvc.GetPositionCheckList(this.User.AccCode+LimsCustomerpositionName, thrOrgList)
+		for _, value := range entitys {
+			strPositionList += strconv.Itoa(value.Id) + ","
+		}
+		strPositionList += "0"
+	}
+
+	if len(strPositionList) > 0 {
+		where = where + " and PositionCheckId in ('" + strPositionList + "')"
+	}
+
+	svc := limscheckequipmentlist.GetLimsCheckEquipmentListService(utils.DBE)
+	var list []limscheckequipmentlist.LimsCheckEquipmentList
+	svc.GetEntitysByWhere(this.User.AccCode+LimsCheckEquipmentListName, where, &list)
+
+	//var title []string
+	filetitle := "设备台账"
+	//自定义显示列
+	showcolumnarr := "设备类型,编号,规格型号,制造厂家,检测地点,安装位置,所属单位,上次检测日期,检测周期,下次检测日期"
+	//titlestring := "TemplateTypeName,CustNo,Spec,Manufacturer,PositionCheck,Position,LastCheckDate,Cycle"
+	//title = strings.Split(titlestring, ",")
+	f := xlsx.NewFile()
+	sheet, _ := f.AddSheet(filetitle)
+	//rowhead := sheet.AddRow()
+	//rowhead.WriteSlice(&title, -1)
+	cellname := strings.Split(showcolumnarr, ",")
+	row := sheet.AddRow()
+	row.WriteSlice(&cellname, -1)
+
+	for _, v := range list {
+		datastring := v.TemplateTypeName + "," + v.CustNo + "," + v.Spec + "," + v.Manufacturer + "," + v.PositionCheck + "," + v.Position + "," + v.Departmentname + "," + utils.ToStr(v.LastCheckDate.Format("2006-01-02")) + "," + strconv.FormatFloat(float64(v.Cycle), 'f', 0, 64) + v.CycleUnit + "," + utils.ToStr(v.NextCheckDate.Format("2006-01-02"))
+
+		cellname := strings.Split(datastring, ",")
+		row := sheet.AddRow()
+		row.WriteSlice(&cellname, -1)
+	}
+
+	for c, cl := 0, len(sheet.Cols); c < cl; c++ {
+		sheet.Cols[c].Width = 20
+	}
+	//this.SaveSampleXlsx(filetitle, title, showcolumnarr, list, f)
+
+	dir := "static/file/excel/report/" + this.GetAccode()
+	SaveDirectory(dir)
+	path := dir + "/" + utils.TimeFormat(time.Now(), "200612") + filetitle + ".xlsx"
+	f.Save(path)
+	this.Data["json"] = this.Ctx.Request.Host + "/" + path
+	this.ServeJSON()
+}

+ 7 - 0
src/dashoo.cn/frontend_web/src/api/lims/limscheckequipmentlist.js

@@ -44,5 +44,12 @@ export default {
       method: 'GET',
       params: params
     })
+  },
+  exportExcelAll (params, myAxios) {
+    return myAxios({
+      url: '/limscheckequipmentlist/exportexcelall',
+      method: 'get',
+      params: params
+    })
   }
 }

+ 17 - 7
src/dashoo.cn/frontend_web/src/pages/lims/checkequipmentlist/index.vue

@@ -16,7 +16,7 @@
             <span>
               <i class="icon icon-table2"></i>
             </span>
-         
+
             <el-form ref="form" :inline="true" style="float: right; margin-top: -10px">
               <el-form-item label="状态">
                  <el-select v-model="statusValue" clearable  @change="ProjectTypeChangeHandler" @clear="ProjectTypeClearHandler" placeholder="请选择" size="mini">
@@ -45,8 +45,9 @@
                 </el-dropdown>
               </el-form-item>
               <el-form-item>
-              <el-button type="primary" size="mini" style="" @click="NewEntity">添加</el-button>
-              </el-form-item> 
+                <el-button type="primary" size="mini" style="" @click="NewEntity">添加</el-button>
+                <el-button type="primary" size="mini" @click="exportExcel">导出</el-button>
+              </el-form-item>
             </el-form>
           </div>
           <el-alert title="提示: 已过期为【红色】, 一个月内到期为【黄色】,正常为【绿色】" type="warning" :closable="false">
@@ -82,7 +83,7 @@
                 {{ jstimehandle(scope.row.NextCheckDate+'') }}
               </template>
             </el-table-column>
-            
+
           </el-table>
           <div class="bottom clearfix">
             <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
@@ -154,7 +155,7 @@
           <el-input-number v-model="formData.OrderNo" :min="1" style="width:100%" placeholder="请输入"></el-input-number>
         </el-form-item>
 
-      
+
 
         <el-form-item label="设备名称" :label-width="formLabelWidth">
           <el-input v-model="formData.DeviceName" autocomplete="off"></el-input>
@@ -626,6 +627,15 @@
         this.formData.ModifiedUserId = 0
         this.formData.ModifiedBy = ''
       },
+      exportExcel () {
+        let params = {
+          PositionAllTypeId: this.selectNodeId + '',
+        }
+        api.exportExcelAll(params, this.$axios).then(res => {
+          this.loading = false
+          window.location = 'http://' + res.data
+        })
+      },
 
       handlePositionChange (value) {
         this.formData.PositionCheckId = value[0]
@@ -656,7 +666,7 @@
           })
           return
         }
-  
+
         if (this.PositionList.length !== 2) {
           this.$message({
             type: 'warning',
@@ -758,7 +768,7 @@
       display: table;
       content: "";
   }
-  
+
   .clearfix:after {
       clear: both
   }