| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- package lims
- import (
- "dashoo.cn/business2/parameter"
- "dashoo.cn/backend/api/business/instrument"
- "dashoo.cn/backend/api/business/limscustomerposition"
- "dashoo.cn/backend/api/business/limsdataentry"
- "encoding/json"
- "strings"
- "time"
- "dashoo.cn/business2/userRole"
- "dashoo.cn/backend/api/business/baseUser"
- "dashoo.cn/backend/api/business/items"
- "dashoo.cn/backend/api/business/Limsreportzuhq"
- svccustomer "dashoo.cn/backend/api/business/customer"
- . "dashoo.cn/backend/api/controllers"
- "dashoo.cn/utils"
- )
- type LimsReportZuhqController struct {
- BaseController
- }
- // @Title 获取列表
- // @Description get user by token
- // @Success 200 {object} []limsreportzuhq.LimsReportZuhq
- // @router /list [get]
- func (this *LimsReportZuhqController) GetEntityList() {
- //获取分页信息
- page := this.GetPageInfoForm()
- where := " 1=1 "
- orderby := "OrderNo,Id"
- asc := true
- Order := this.GetString("Order")
- Prop := this.GetString("Prop")
- if Order != "" && Prop != "" {
- orderby = Prop
- if Order == "asc" {
- asc = true
- }
- }
- OrderNo := this.GetString("OrderNo")
- Position := this.GetString("Position")
- CustNo := this.GetString("CustNo")
- CheckDate := this.GetString("CheckDate")
- Temperature := this.GetString("Temperature")
- Spec := this.GetString("Spec")
- Manufacturer := this.GetString("Manufacturer")
- StatusA := this.GetString("Status")
- StandardCode := this.GetString("StandardCode")
- MainProducts := this.GetString("MainProducts")
- Remark1 := this.GetString("Remark1")
- Remark2 := this.GetString("Remark2")
- DataEntryId := this.GetString("DataEntryId")
- if DataEntryId != "" {
- where = where + " and DataEntryId =" + DataEntryId
- } else {
- where = where + " and DataEntryId =" + "0"
- }
- if OrderNo != "" {
- where = where + " and OrderNo like '%" + OrderNo + "%'"
- }
- if Position != "" {
- where = where + " and Position like '%" + Position + "%'"
- }
- if CustNo != "" {
- where = where + " and CustNo like '%" + CustNo + "%'"
- }
- if Temperature != "" {
- where = where + " and Temperature like '%" + Temperature + "%'"
- }
- if Spec != "" {
- where = where + " and Spec like '%" + Spec + "%'"
- }
- if Manufacturer != "" {
- where = where + " and Manufacturer like '%" + Manufacturer + "%'"
- }
- if StatusA != "" {
- where = where + " and Status like '%" + StatusA + "%'"
- }
- if StandardCode != "" {
- where = where + " and StandardCode like '%" + StandardCode + "%'"
- }
- if MainProducts != "" {
- where = where + " and MainProducts like '%" + MainProducts + "%'"
- }
- if Remark1 != "" {
- where = where + " and Remark1 like '%" + Remark1 + "%'"
- }
- if Remark2 != "" {
- where = where + " and Remark2 like '%" + Remark2 + "%'"
- }
- if CheckDate != "" {
- dates := strings.Split(CheckDate, ",")
- if len(dates) == 2 {
- minDate := dates[0]
- maxDate := dates[1]
- where = where + " and CheckDate>='" + minDate + "' and CheckDate<='" + maxDate + "'"
- }
- }
- svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
- var list []Limsreportzuhq.LimsReportZuhq
- total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
- var list1 []Limsreportzuhq.LimsReportZuhq
- svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, 1,total, orderby, asc, &list1, where)
- var maxorderno = 0
- for i := 0; i < len(list1); i++ {
- if maxorderno < list1[i].OrderNo {
- maxorderno = list1[i].OrderNo
- }
- }
- var datainfo DataInfo
- datainfo.Items = list
- datainfo.CurrentItemCount = total
- datainfo.PageIndex = page.CurrentPage
- datainfo.ItemsPerPage = page.Size
- datainfo.StartIndex = int64(maxorderno)
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 获取字典列表
- // @Description get user by token
- // @Success 200 {object} map[string]interface{}
- // @router /dictlist [get]
- func (this *LimsReportZuhqController) GetDictList() {
- dictList := make(map[string]interface{})
- dictSvc := items.GetItemsService(utils.DBE)
- userSvc := baseUser.GetBaseUserService(utils.DBE)
- customerSvc := svccustomer.GetCustomerService(utils.DBE)
- paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
- itemSvc := items.GetItemsService(utils.DBE)
- instsvc := instrument.GetInstrumentService(utils.DBE)
- dictList["Position"] = dictSvc.GetKeyValueItems("Position", this.User.AccCode)
- dictList["PositionCheck"] = dictSvc.GetKeyValueItems("PositionCheck", this.User.AccCode)
- dictList["ProductStatus"] = dictSvc.GetKeyValueItems("ProductStatus", this.User.AccCode)
- dictList["YxCheckForm"] = dictSvc.GetKeyValueItems("YxCheckForm", this.User.AccCode)
- var userEntity userRole.Base_User
- userSvc.GetEntityById(this.User.Id, &userEntity)
- dictList["Supervisers"] = userSvc.GetUserListByDepartmentId(this.User.AccCode, userEntity.Departmentid)
- var dictCustomer []svccustomer.Customer
- customerSvc.GetEntitysByWhere(this.User.AccCode + CustomerName, "", &dictCustomer)
- dictList["EntrustCorp"] = &dictCustomer
- where := "ItemsId=246"
- dictList["StandardItems"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
- dictList["DefaultStandardZhq"] = paramSvc.GetBaseparameterMessage("s5OVE", "paramset", "StandardZhq")
- ////安全附件检测仪
- //where = "ParentId=193"
- //dictList["SafAccDetector"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
- //
- ////热式气体质量流量计
- //where = "ParentId=198"
- //dictList["GasFlowMeter"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
- //
- ////差压变送器
- //where = "ParentId=203"
- //dictList["DifPressTran"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
- //常见问题
- where = "ParentId=126"
- dictList["ProblemItems"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
- //常见问题位置
- where = "ParentId=120"
- dictList["ProblemLocation"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
- //规格型号
- where = "ParentId=286"
- dictList["Spec1"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
- where = "ParentId=290"
- dictList["Spec2"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
- var PressureLeak []items.LimsPressureLeak
- customerSvc.GetEntitysByWhere(this.User.AccCode + LimsPressureLeakName, "", &PressureLeak)
- dictList["PressureLeak"] = &PressureLeak
- // 检测仪器--压力变送器
- var list []instrument.Instrument
- where = "Classification='压力变送器'"
- instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where,&list)
- dictList["DifPressTran"] = list
- // 检测仪器--安全附件检测仪
- var list1 []instrument.Instrument
- where = "Classification='安全附件检测仪'"
- instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where,&list1)
- dictList["SafAccDetector"] = list1
- // 检测仪器--热式气体质量流量计
- var list2 []instrument.Instrument
- where = "Classification='热式气体质量流量计'"
- instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where,&list2)
- dictList["GasFlowMeter"] = list2
- // 相关联的检测仪器
- var instrumentgroup []instrument.LimsInstrumentGroup
- where = "1 = 1"
- instsvc.GetEntitysByWhere(this.User.AccCode+LimsInstrumentGroup, where,&instrumentgroup)
- dictList["instrumentgroup"] = instrumentgroup
- var datainfo DataInfo
- datainfo.Items = dictList
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 获取实体
- // @Description 获取实体
- // @Success 200 {object} limsreportzuhq.LimsReportZuhq
- // @router /get/:id [get]
- func (this *LimsReportZuhqController) GetEntity() {
- Id := this.Ctx.Input.Param(":id")
- var model Limsreportzuhq.LimsReportZuhq
- svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
- svc.GetEntityByIdBytbl(this.User.AccCode+LimsReportZuhqName, Id, &model)
- this.Data["json"] = &model
- this.ServeJSON()
- }
- // @Title 添加
- // @Description 新增
- // @Param body body limsreportzuhq.LimsReportZuhq
- // @Success 200 {object} controllers.Request
- // @router /add [post]
- func (this *LimsReportZuhqController) AddEntity() {
- var model Limsreportzuhq.LimsReportZuhq
- var jsonBlob = this.Ctx.Input.RequestBody
- svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
- json.Unmarshal(jsonBlob, &model)
- model.CreateOn = time.Now()
- model.CreateBy = this.User.Realname
- model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
- _, err := svc.InsertEntityBytbl(this.User.AccCode+LimsReportZuhqName, &model)
- var errinfo ErrorDataInfo
- if err == nil {
- //新增
- errinfo.Message = "添加成功!"
- errinfo.Code = 0
- errinfo.Item = model.Id
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 修改实体
- // @Description 修改实体
- // @Param body body limsreportzuhq.LimsReportZuhq
- // @Success 200 {object} controllers.Request
- // @router /update/:id [post]
- func (this *LimsReportZuhqController) UpdateEntity() {
- id := this.Ctx.Input.Param(":id")
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var model Limsreportzuhq.LimsReportZuhq
- svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
- var jsonBlob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonBlob, &model)
- model.ModifiedOn = time.Now()
- model.ModifiedBy = this.User.Realname
- model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- cols := []string{
- "Id",
- "EId",
- "TaskBalanceId",
- "DataEntryId",
- "OrderNo",
- "Position",
- "PositionId",
- "PositionCheck",
- "PositionCheckId",
- "StandardDesc",
- "CustNo",
- "PUType",
- "SafAccDetector",
- "GasFlowMeter",
- "DifPressTran",
- "CheckDate",
- "PaDiff",
- "Temperature",
- "Spec",
- "Manufacturer",
- "Status",
- "StandardCode",
- "MainProducts",
- "VentVolume1",
- "VentVolume2",
- "VentVolume3",
- "VentVolume4",
- "PyPapot",
- "PyPa1",
- "PyPa2",
- "PyPa3",
- "PyPaAvg",
- "PwPa1",
- "PwPa2",
- "PwPa3",
- "PwPaAvg",
- "Remark1",
- "Remark2",
- "CreateOn",
- "CreateUserId",
- "CreateBy",
- "ModifiedOn",
- "ModifiedUserId",
- "ModifiedBy",
- }
- err := svc.UpdateEntityBytbl(this.User.AccCode+LimsReportZuhqName, id, &model, cols)
- if err == nil {
- errinfo.Message = "修改成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 删除单条信息
- // @Description
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /delete/:Id [delete]
- func (this *LimsReportZuhqController) DeleteEntity() {
- Id := this.Ctx.Input.Param(":Id")
- var errinfo ErrorInfo
- if Id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var model Limsreportzuhq.LimsReportZuhq
- var entityempty Limsreportzuhq.LimsReportZuhq
- svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
- opdesc := "删除-" + Id
- err := svc.DeleteOperationAndWriteLogBytbl(this.User.AccCode+LimsReportZuhqName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报")
- if err == nil {
- errinfo.Message = "删除成功"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 获取委托方信息
- // @Description 获取委托方信息
- // @Success 200 object} map[string]interface{}
- // @router /getEntrustCorp/:id [get]
- func (this *LimsReportZuhqController) GetEntrustCorpItems() {
- dictList := make(map[string]interface{})
- cId := this.Ctx.Input.Param(":id")
- var model []limscustomerposition.LimsCustomerPosition
- svc := limscustomerposition.GetLimsCustomerpositionService(utils.DBE)
- where := "CustomerId=" + cId + " and ParentId = 0"
- svc.GetEntitysByWhere(this.User.AccCode+LimsCustomerpositionName, where,&model)
- dictList["PositionCheck"] = model
- var Positionmodel []limscustomerposition.LimsCustomerPosition
- where = "CustomerId=" + cId + " and ParentId <> 0"
- svc.GetEntitysByWhere(this.User.AccCode+LimsCustomerpositionName,where, &Positionmodel)
- dictList["Position"] = Positionmodel
- var datainfo DataInfo
- datainfo.Items = dictList
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 添加运行记录
- // @Description 新增
- // @Param body body instrument.InstrumenRunRecord
- // @Success 200 {object} controllers.Request
- // @router /addRunRecord/:Id [post]
- func (this *LimsReportZuhqController) AddRunRecord() {
- Id := this.Ctx.Input.Param(":Id")
- var dataentry limsdataentry.LimsDateEntry
- svc := limsdataentry.GetLimsDataEntryService(utils.DBE)
- svc.GetEntityByIdBytbl(this.User.AccCode+LimsDateEntryName, Id, &dataentry)
- where := "ContractNo = '" + dataentry.DataEntryCode + "'"
- svc.DeleteEntityBytbl(this.User.AccCode+InstrumenRunRecordName, where)
- instruments1 := strings.Split(dataentry.Instrument1, ",")
- for i := 0; i < len(instruments1); i++ {
- if instruments1[i] != "" {
- var instlist instrument.Instrument
- var runrecord instrument.InstrumenRunRecord
- where := "Code='" + instruments1[i] + "'"
- svc.GetEntityByWhere(this.User.AccCode+InstrumentName, where, &instlist)
- runrecord.InstrumentId = instlist.Id
- runrecord.InstrumenCode = instlist.Code
- runrecord.InstrumenName = instlist.Name
- runrecord.ContractNo = dataentry.DataEntryCode
- runrecord.CreateOn = time.Now()
- runrecord.CreateBy = this.User.Realname
- runrecord.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- svc.InsertEntityBytbl(this.User.AccCode+InstrumenRunRecordName, &runrecord)
- }
- }
- instruments2 := strings.Split(dataentry.Instrument2, ",")
- for i := 0; i < len(instruments2); i++ {
- if instruments2[i] != "" {
- var instlist instrument.Instrument
- var runrecord instrument.InstrumenRunRecord
- where := "Code='" + instruments2[i] + "'"
- svc.GetEntityByWhere(this.User.AccCode+InstrumentName, where, &instlist)
- runrecord.InstrumentId = instlist.Id
- runrecord.InstrumenCode = instlist.Code
- runrecord.InstrumenName = instlist.Name
- runrecord.ContractNo = dataentry.DataEntryCode
- runrecord.CreateOn = time.Now()
- runrecord.CreateBy = this.User.Realname
- runrecord.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- svc.InsertEntityBytbl(this.User.AccCode+InstrumenRunRecordName, &runrecord)
- }
- }
- instruments3 := strings.Split(dataentry.Instrument3, ",")
- for i := 0; i < len(instruments3); i++ {
- if instruments3[i] != "" {
- var instlist instrument.Instrument
- var runrecord instrument.InstrumenRunRecord
- where := "Code='" + instruments3[i] + "'"
- svc.GetEntityByWhere(this.User.AccCode+InstrumentName, where, &instlist)
- runrecord.InstrumentId = instlist.Id
- runrecord.InstrumenCode = instlist.Code
- runrecord.InstrumenName = instlist.Name
- runrecord.ContractNo = dataentry.DataEntryCode
- runrecord.CreateOn = time.Now()
- runrecord.CreateBy = this.User.Realname
- runrecord.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- svc.InsertEntityBytbl(this.User.AccCode+InstrumenRunRecordName, &runrecord)
- }
- }
- }
|