| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- package lims
- import (
- "dashoo.cn/backend/api/business/devicestatistics"
- "dashoo.cn/backend/api/business/organize"
- . "dashoo.cn/backend/api/controllers"
- "dashoo.cn/utils"
- "fmt"
- "strconv"
- "strings"
- "time"
- )
- type DeviceStatisticsController struct {
- BaseController
- }
- // @Title 获取列表
- // @Description get user by token
- // @Success 200 {object}
- // @router /list [get]
- func (this *DeviceStatisticsController) GetEntityList() {
- unitId := this.GetString("unitCheckId")
- // svcPerm := permission.GetPermissionService(utils.DBE)
- //isauth := svcPerm.IsAuthorized(this.User.Id, "Administrator")
- // organizeSvc := organize.GetOrganizeService(utils.DBE)
- // thrunitId := organizeSvc.GetMyThrUnitDepartmentId(this.User.DepartmentId)
- 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"
- organizeSvc := organize.GetOrganizeService(utils.DBE)
- thrId := organizeSvc.GetMyThrUnitDepartmentId(this.User.DepartmentId)
- thrIds := ""
- ethrIds := ""
- //unitId := ""
- wheret := ""
- if thrId == "100001219" || thrId == "100001215" {
- if unitId != "" {
- throrg := organizeSvc.GetAllThirdChildByTopId(unitId, "")
- if throrg == nil {
- thrIds = "-1"
- } else {
- for _, item := range throrg {
- thrIds += strconv.Itoa(item.Id) + ","
- }
- thrIds = strings.Trim(thrIds, ",")
- ethrIds = organizeSvc.GetAllChildById(unitId)
- }
- }
- } else {
- //if thrId == this.User.DepartmentId {
- unitId = organizeSvc.GetMyUnitDepartmentId(this.User.DepartmentId)
- //var throrg []organize.Base_Organize
- throrg := organizeSvc.GetAllThirdChildByTopId(unitId, "")
- for _, item := range throrg {
- thrIds += strconv.Itoa(item.Id) + ","
- }
- ethrIds = organizeSvc.GetAllChildById(unitId)
- thrIds = strings.Trim(thrIds, ",")
- //} else {
- // ethrIds = thrId
- //}
- }
- if thrIds != "" {
- wheret = " and b.TestDepartId in (" + thrIds + ")"
- }
- wheree := ""
- if ethrIds != "" {
- wheree = " and DepartmentId in (" + ethrIds + ")"
- }
- where := "(a.CreateOn < DATE_ADD(CURDATE()-DAY(CURDATE())+1,INTERVAL 1 MONTH)) and a.CheckResult != ''" + wheret
- whereYno := "(a.CreateOn < DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAYOFYEAR(NOW())-1 DAY),INTERVAL 1 YEAR)) and a.CheckResult='×' " + wheret
- whereY := "(a.CreateOn < DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAYOFYEAR(NOW())-1 DAY),INTERVAL 1 YEAR)) and a.CheckResult='○' " + wheret
- if thrId != "100001219" {
- // 防雷装置(等电位)
- 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 " + wheree
- numEQ := svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
- numWM := svc.GetWaitCountsMonth("187")
- numWY := svc.GetWaitCountsYear("187")
- deviceEQ.DeviceName = "防雷装置(等电位)"
- deviceEQ.DeviceQty = int(numEQ)
- deviceEQ.WaitYear = int(numWY)
- deviceEQ.WaitMonth = int(numWM)
- 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 " + wheree
- numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
- numWM = svc.GetWaitCountsMonth("286")
- numWY = svc.GetWaitCountsYear("286")
- deviceLPT.DeviceName = "防雷装置"
- deviceLPT.DeviceQty = numEQ
- deviceLPT.WaitYear = int(numWY)
- deviceLPT.WaitMonth = int(numWM)
- 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" + wheree
- numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
- numWM = svc.GetWaitCountsMonth("181")
- numWY = svc.GetWaitCountsYear("181")
- deviceLP.DeviceName = "漏电保护器"
- deviceLP.DeviceQty = numEQ
- deviceLP.WaitYear = int(numWY)
- deviceLP.WaitMonth = int(numWM)
- 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 " + wheree
- numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
- numWM = svc.GetWaitCountsMonth("179")
- numWY = svc.GetWaitCountsYear("179")
- deviceEG.DeviceName = "电气接地"
- deviceEG.DeviceQty = numEQ
- deviceEG.WaitYear = int(numWY)
- deviceEG.WaitMonth = int(numWM)
- 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)
- }
- if thrId != "100001215" {
- whereYno = "(a.CreateOn < DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAYOFYEAR(NOW())-1 DAY),INTERVAL 1 YEAR)) and a.CheckResult LIKE '%不合格%'" + wheret
- whereY = "(a.CreateOn < DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAYOFYEAR(NOW())-1 DAY),INTERVAL 1 YEAR)) and a.CheckResult LIKE '%合格%' AND CheckResult NOT LIKE '%不合格%' " + wheret
- //阻火器 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" + wheree
- numEQ := svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
- numWM := svc.GetWaitCountsMonth("156")
- numWY := svc.GetWaitCountsYear("156")
- deviceZHQ.DeviceName = "阻火器"
- deviceZHQ.DeviceQty = numEQ
- deviceZHQ.WaitYear = int(numWY)
- deviceZHQ.WaitMonth = int(numWM)
- 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 " + wheree
- numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
- numWM = svc.GetWaitCountsMonth("183")
- numWY = svc.GetWaitCountsYear("183")
- deviceHXF.DeviceName = "呼吸阀"
- deviceHXF.DeviceQty = numEQ
- deviceHXF.WaitYear = int(numWY)
- deviceHXF.WaitMonth = int(numWM)
- 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 " + wheree
- numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
- numWM = svc.GetWaitCountsMonth("154")
- numWY = svc.GetWaitCountsYear("154")
- deviceYYF.DeviceName = "液压安全阀"
- deviceYYF.DeviceQty = numEQ
- deviceYYF.WaitYear = int(numWY)
- deviceYYF.WaitMonth = int(numWM)
- 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 " + wheree
- numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
- numWM = svc.GetWaitCountsMonth("189")
- numWY = svc.GetWaitCountsYear("189")
- deviceKQPM.DeviceName = "空气泡沫产生器"
- deviceKQPM.DeviceQty = numEQ
- deviceKQPM.WaitYear = int(numWY)
- deviceKQPM.WaitMonth = int(numWM)
- 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 " + wheree
- numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
- numWM = svc.GetWaitCountsMonth("141")
- numWY = svc.GetWaitCountsYear("141")
- deviceYL.DeviceName = "游梁式抽油机"
- deviceYL.DeviceQty = numEQ
- deviceYL.WaitYear = int(numWY)
- deviceYL.WaitMonth = int(numWM)
- 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 " + wheree
- numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
- numWM = svc.GetWaitCountsMonth("173")
- numWY = svc.GetWaitCountsYear("173")
- deviceWYL.DeviceName = "无游梁式抽油机"
- deviceWYL.DeviceQty = numEQ
- deviceWYL.WaitYear = int(numWY)
- deviceWYL.WaitMonth = int(numWM)
- 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()
- }
- // @Title 获取字典列表
- // @Description get user by token
- // @Success 200 {object} map[string]interface{}
- // @router /dictlist [get]
- func (this *DeviceStatisticsController) GetDictList() {
- dictList := make(map[string]interface{})
- var unitorg []organize.Base_Organize
- svc := organize.GetOrganizeService(utils.DBE)
- //unitId := svc.GetMyUnitDepartmentId(this.User.DepartmentId)
- //unitorg = svc.GetAllThirdChildByTopId(unitId, "")
- where := "Category='unit'"
- svc.GetEntities(&unitorg, where)
- dictList["unitorg"] = unitorg
- var datainfo DataInfo
- datainfo.Items = dictList
- 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())
- }
|