|
|
@@ -0,0 +1,218 @@
|
|
|
+package lims
|
|
|
+
|
|
|
+import (
|
|
|
+ "dashoo.cn/backend/api/business/devicestatistics"
|
|
|
+ . "dashoo.cn/backend/api/controllers"
|
|
|
+ "dashoo.cn/utils"
|
|
|
+ "fmt"
|
|
|
+ "strconv"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+type DeviceStatisticsController struct {
|
|
|
+ BaseController
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// @Title 获取列表
|
|
|
+// @Description get user by token
|
|
|
+// @Success 200 {object}
|
|
|
+// @router /list [get]
|
|
|
+func (this *DeviceStatisticsController) GetEntityList() {
|
|
|
+ var devicelist []devicestatistics.DeviceStatistics
|
|
|
+ svc := devicestatistics.GetDeviceStatisticsService(utils.DBE)
|
|
|
+ fromdate := GetFirstDateOfMonth(time.Now()).Format("2006-01-02 15:04:05")
|
|
|
+ todate := GetLastDateOfMonth(time.Now()).Format("2006-01-02") + " 23:59:59"
|
|
|
+
|
|
|
+ where := "(CreateOn BETWEEN '" + fromdate + "' AND '" + todate + "') and CheckResult != ''"
|
|
|
+ fromdateyear := strconv.Itoa(time.Now().Year()) + "-01-01 00:00:00"
|
|
|
+ todateyear := strconv.Itoa(time.Now().Year()) + "-12-31 23:59:59"
|
|
|
+ whereYno := "(CreateOn BETWEEN '" + fromdateyear + "' AND '" + todateyear + "') and CheckResult='×'"
|
|
|
+ whereY := "(CreateOn BETWEEN '" + fromdateyear + "' AND '" + todateyear + "') and CheckResult='○'"
|
|
|
+
|
|
|
+ // 防雷装置(等电位)
|
|
|
+ var deviceEQ devicestatistics.DeviceStatistics
|
|
|
+ totalYearNo := svc.GetCountsByDate(this.User.AccCode + LimsReportEquipotentName, whereYno)
|
|
|
+ totalYear := svc.GetCountsByDate(this.User.AccCode + LimsReportEquipotentName, whereY)
|
|
|
+ num := svc.GetCountsByDate(this.User.AccCode + LimsReportEquipotentName, where)
|
|
|
+ whereN := "TemplateTypeId=187"
|
|
|
+ numEQ := svc.GetCountsByDate(this.User.AccCode + LimsCheckEquipmentListName, whereN)
|
|
|
+ deviceEQ.DeviceName = "防雷装置(等电位)"
|
|
|
+ deviceEQ.DeviceQty = int(numEQ)
|
|
|
+ deviceEQ.FinishMonth = int(num)
|
|
|
+ deviceEQ.FinishYear = int(totalYearNo) + int(totalYear)
|
|
|
+ if deviceEQ.FinishYear != 0 {
|
|
|
+ deviceEQ.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
|
|
|
+ }
|
|
|
+ devicelist = append(devicelist, deviceEQ)
|
|
|
+
|
|
|
+ // 防雷装置
|
|
|
+ var deviceLPT devicestatistics.DeviceStatistics
|
|
|
+ totalYearNo = svc.GetCountsByDate(this.User.AccCode + LimsReportLightProtectName, whereYno)
|
|
|
+ totalYear = svc.GetCountsByDate(this.User.AccCode + LimsReportLightProtectName, whereY)
|
|
|
+ num = svc.GetCountsByDate(this.User.AccCode + LimsReportLightProtectName, where)
|
|
|
+ whereN ="TemplateTypeId=286"
|
|
|
+ numEQ = svc.GetCountsByDate(this.User.AccCode + LimsCheckEquipmentListName, whereN)
|
|
|
+ deviceLPT.DeviceName = "防雷装置"
|
|
|
+ deviceLPT.DeviceQty = numEQ
|
|
|
+ deviceLPT.FinishMonth = int(num)
|
|
|
+ deviceLPT.FinishYear = int(totalYearNo) + int(totalYear)
|
|
|
+ if deviceLPT.FinishYear != 0 {
|
|
|
+ deviceLPT.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
|
|
|
+ }
|
|
|
+ devicelist = append(devicelist, deviceLPT)
|
|
|
+
|
|
|
+ // 漏电保护器
|
|
|
+ var deviceLP devicestatistics.DeviceStatistics
|
|
|
+ totalYearNo = svc.GetCountsByDate(this.User.AccCode + LimsReportLeakProtectName, whereYno)
|
|
|
+ totalYear = svc.GetCountsByDate(this.User.AccCode + LimsReportLeakProtectName, whereY)
|
|
|
+ num = svc.GetCountsByDate(this.User.AccCode + LimsReportLeakProtectName, where)
|
|
|
+ whereN ="TemplateTypeId=181"
|
|
|
+ numEQ = svc.GetCountsByDate(this.User.AccCode + LimsCheckEquipmentListName, whereN)
|
|
|
+ deviceLP.DeviceName = "漏电保护器"
|
|
|
+ deviceLP.DeviceQty = numEQ
|
|
|
+ deviceLP.FinishMonth = int(num)
|
|
|
+ deviceLP.FinishYear = int(totalYearNo) + int(totalYear)
|
|
|
+ if deviceLP.FinishYear != 0 {
|
|
|
+ deviceLP.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
|
|
|
+ }
|
|
|
+ devicelist = append(devicelist, deviceLP)
|
|
|
+
|
|
|
+ // 电气接地
|
|
|
+ var deviceEG devicestatistics.DeviceStatistics
|
|
|
+ totalYearNo = svc.GetCountsByDate(this.User.AccCode + LimsReportElecGroundName, whereYno)
|
|
|
+ totalYear = svc.GetCountsByDate(this.User.AccCode + LimsReportElecGroundName, whereY)
|
|
|
+ num = svc.GetCountsByDate(this.User.AccCode + LimsReportElecGroundName, where)
|
|
|
+ whereN ="TemplateTypeId=179"
|
|
|
+ numEQ = svc.GetCountsByDate(this.User.AccCode + LimsCheckEquipmentListName, whereN)
|
|
|
+ deviceEG.DeviceName = "电气接地"
|
|
|
+ deviceEG.DeviceQty = numEQ
|
|
|
+ deviceEG.FinishMonth = int(num)
|
|
|
+ deviceEG.FinishYear = int(totalYearNo) + int(totalYear)
|
|
|
+ if deviceEG.FinishYear != 0 {
|
|
|
+ deviceEG.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
|
|
|
+ }
|
|
|
+ devicelist = append(devicelist, deviceEG)
|
|
|
+
|
|
|
+ whereYno = "(CreateOn BETWEEN '" + fromdateyear + "' AND '" + todateyear + "') and CheckResult LIKE '%不合格%' "
|
|
|
+ whereY = "(CreateOn BETWEEN '" + fromdateyear + "' AND '" + todateyear + "') and CheckResult LIKE '%合格%'"
|
|
|
+ //阻火器 LimsReportZuhq
|
|
|
+ var deviceZHQ devicestatistics.DeviceStatistics
|
|
|
+ totalYearNo = svc.GetCountsByDate(this.User.AccCode + LimsReportZuhqName, whereYno)
|
|
|
+ totalYear = svc.GetCountsByDate(this.User.AccCode + LimsReportZuhqName, whereY)
|
|
|
+ num = svc.GetCountsByDate(this.User.AccCode + LimsReportZuhqName, where)
|
|
|
+ whereN ="TemplateTypeId=156"
|
|
|
+ numEQ = svc.GetCountsByDate(this.User.AccCode + LimsCheckEquipmentListName, whereN)
|
|
|
+ deviceZHQ.DeviceName = "阻火器"
|
|
|
+ deviceZHQ.DeviceQty = numEQ
|
|
|
+ deviceZHQ.FinishMonth = int(num)
|
|
|
+ deviceZHQ.FinishYear = int(totalYearNo) + int(totalYear)
|
|
|
+ if deviceZHQ.FinishYear != 0 {
|
|
|
+ deviceZHQ.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
|
|
|
+ }
|
|
|
+ devicelist = append(devicelist, deviceZHQ)
|
|
|
+
|
|
|
+ // 呼吸阀 LimsReportHuxf
|
|
|
+ var deviceHXF devicestatistics.DeviceStatistics
|
|
|
+ totalYearNo = svc.GetCountsByDate(this.User.AccCode + LimsReportHuxfName, whereYno)
|
|
|
+ totalYear = svc.GetCountsByDate(this.User.AccCode + LimsReportHuxfName, whereY)
|
|
|
+ num = svc.GetCountsByDate(this.User.AccCode + LimsReportHuxfName, where)
|
|
|
+ whereN ="TemplateTypeId=183"
|
|
|
+ numEQ = svc.GetCountsByDate(this.User.AccCode + LimsCheckEquipmentListName, whereN)
|
|
|
+ deviceHXF.DeviceName = "呼吸阀"
|
|
|
+ deviceHXF.DeviceQty = numEQ
|
|
|
+ deviceHXF.FinishMonth = int(num)
|
|
|
+ deviceHXF.FinishYear = int(totalYearNo) + int(totalYear)
|
|
|
+ if deviceHXF.FinishYear != 0 {
|
|
|
+ deviceHXF.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
|
|
|
+ }
|
|
|
+ devicelist = append(devicelist, deviceHXF)
|
|
|
+
|
|
|
+ // 液压安全阀 LimsReportYeyaqf
|
|
|
+ var deviceYYF devicestatistics.DeviceStatistics
|
|
|
+ totalYearNo = svc.GetCountsByDate(this.User.AccCode + LimsReportYeyaqfName, whereYno)
|
|
|
+ totalYear = svc.GetCountsByDate(this.User.AccCode + LimsReportYeyaqfName, whereY)
|
|
|
+ num = svc.GetCountsByDate(this.User.AccCode + LimsReportYeyaqfName, where)
|
|
|
+ whereN ="TemplateTypeId=154"
|
|
|
+ numEQ = svc.GetCountsByDate(this.User.AccCode + LimsCheckEquipmentListName, whereN)
|
|
|
+ deviceYYF.DeviceName = "液压安全阀"
|
|
|
+ deviceYYF.DeviceQty = numEQ
|
|
|
+ deviceYYF.FinishMonth = int(num)
|
|
|
+ deviceYYF.FinishYear = int(totalYearNo) + int(totalYear)
|
|
|
+ if deviceYYF.FinishYear != 0 {
|
|
|
+ deviceYYF.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
|
|
|
+ }
|
|
|
+ devicelist = append(devicelist, deviceYYF)
|
|
|
+
|
|
|
+ // 空气泡沫产生器 LimsReportAirFoamGenerator
|
|
|
+ var deviceKQPM devicestatistics.DeviceStatistics
|
|
|
+ totalYearNo = svc.GetCountsByDate(this.User.AccCode + LimsReportKqpmName, whereYno)
|
|
|
+ totalYear = svc.GetCountsByDate(this.User.AccCode + LimsReportKqpmName, whereY)
|
|
|
+ num = svc.GetCountsByDate(this.User.AccCode + LimsReportKqpmName, where)
|
|
|
+ whereN ="TemplateTypeId=189"
|
|
|
+ numEQ = svc.GetCountsByDate(this.User.AccCode + LimsCheckEquipmentListName, whereN)
|
|
|
+ deviceKQPM.DeviceName = "空气泡沫产生器"
|
|
|
+ deviceKQPM.DeviceQty = numEQ
|
|
|
+ deviceKQPM.FinishMonth = int(num)
|
|
|
+ deviceKQPM.FinishYear = int(totalYearNo) + int(totalYear)
|
|
|
+ if deviceKQPM.FinishYear != 0 {
|
|
|
+ deviceKQPM.PassRate,_ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo) + float64(totalYear)))*100), 64)
|
|
|
+ }
|
|
|
+ devicelist = append(devicelist, deviceKQPM)
|
|
|
+
|
|
|
+ // 游梁式抽油机 LimsReportBeamPumpingUnits
|
|
|
+ var deviceYL devicestatistics.DeviceStatistics
|
|
|
+ totalYearNo = svc.GetCountsByDate(this.User.AccCode + LimsReportBeamPumpingUnitName, whereYno)
|
|
|
+ totalYear = svc.GetCountsByDate(this.User.AccCode + LimsReportBeamPumpingUnitName, whereY)
|
|
|
+ num = svc.GetCountsByDate(this.User.AccCode + LimsReportBeamPumpingUnitName, where)
|
|
|
+ whereN ="TemplateTypeId=141"
|
|
|
+ numEQ = svc.GetCountsByDate(this.User.AccCode + LimsCheckEquipmentListName, whereN)
|
|
|
+ deviceYL.DeviceName = "游梁式抽油机"
|
|
|
+ deviceYL.DeviceQty = numEQ
|
|
|
+ deviceYL.FinishMonth = int(num)
|
|
|
+ deviceYL.FinishYear = int(totalYearNo) + int(totalYear)
|
|
|
+ if deviceYL.FinishYear != 0 {
|
|
|
+ deviceYL.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
|
|
|
+ }
|
|
|
+ devicelist = append(devicelist, deviceYL)
|
|
|
+
|
|
|
+ // 无游梁式抽油机 LimsReportNoBeamPumpingUnit
|
|
|
+ var deviceWYL devicestatistics.DeviceStatistics
|
|
|
+ totalYearNo = svc.GetCountsByDate(this.User.AccCode + LimsReportNoBeamPumpingUnitName, whereYno)
|
|
|
+ totalYear = svc.GetCountsByDate(this.User.AccCode + LimsReportNoBeamPumpingUnitName, whereY)
|
|
|
+ num = svc.GetCountsByDate(this.User.AccCode + LimsReportNoBeamPumpingUnitName, where)
|
|
|
+ whereN ="TemplateTypeId=173"
|
|
|
+ numEQ = svc.GetCountsByDate(this.User.AccCode + LimsCheckEquipmentListName, whereN)
|
|
|
+ deviceWYL.DeviceName = "无游梁式抽油机"
|
|
|
+ deviceWYL.DeviceQty = numEQ
|
|
|
+ deviceWYL.FinishMonth = int(num)
|
|
|
+ deviceWYL.FinishYear = int(totalYearNo) + int(totalYear)
|
|
|
+ if deviceWYL.FinishYear != 0 {
|
|
|
+ deviceWYL.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
|
|
|
+ }
|
|
|
+ devicelist = append(devicelist, deviceWYL)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var datainfo ErrorDataInfo
|
|
|
+ datainfo.Item = devicelist
|
|
|
+ this.Data["json"] = &datainfo
|
|
|
+ this.ServeJSON()
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。
|
|
|
+
|
|
|
+func GetFirstDateOfMonth(d time.Time) time.Time {
|
|
|
+ d = d.AddDate(0, 0, -d.Day() + 1)
|
|
|
+ return GetZeroTime(d)
|
|
|
+}
|
|
|
+//获取传入的时间所在月份的最后一天,即某月最后一天的0点。如传入time.Now(), 返回当前月份的最后一天0点时间。
|
|
|
+func GetLastDateOfMonth(d time.Time) time.Time {
|
|
|
+ return GetFirstDateOfMonth(d).AddDate(0, 1, -1)
|
|
|
+}
|
|
|
+//获取某一天的0点时间
|
|
|
+func GetZeroTime(d time.Time) time.Time {
|
|
|
+ return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
|
|
|
+}
|