package oilsupplier import ( "encoding/json" //"fmt" "strconv" "strings" "time" "dashoo.cn/backend/api/business/baseUser" "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub" "dashoo.cn/backend/api/business/oilsupplier/supplierfile" // "dashoo.cn/backend/api/business/oilsupplier/technologyservice" . "dashoo.cn/backend/api/controllers" "dashoo.cn/business/userRole" "dashoo.cn/utils" ) type OilSupplierCertSubController struct { BaseController } // @Title 获取列表 // @Description get user by token // @Success 200 {object} []suppliercertsub.OilSupplierCertSub // @router /list [get] func (this *OilSupplierCertSubController) GetEntityList() { //获取分页信息 page := this.GetPageInfoForm() where := " 1=1 " orderby := "Id" asc := false Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = Prop if Order == "asc" { asc = true } } Id := this.GetString("Id") SupplierId := this.GetString("SupplierId") SupplierCertId := this.GetString("SupplierCertId") SupplierTypeCode := this.GetString("SupplierTypeCode") Code := this.GetString("Code") Name := this.GetString("Name") Remark := this.GetString("Remark") IsDelete := this.GetString("IsDelete") CreateOn := this.GetString("CreateOn") CreateUserId := this.GetString("CreateUserId") CreateBy := this.GetString("CreateBy") ModifiedOn := this.GetString("ModifiedOn") ModifiedUserId := this.GetString("ModifiedUserId") ModifiedBy := this.GetString("ModifiedBy") if Id != "" { where = where + " and Id like '%" + Id + "%'" } if SupplierId != "" { where = where + " and SupplierId like '%" + SupplierId + "%'" } if SupplierCertId != "" { where = where + " and SupplierCertId = '" + SupplierCertId + "'" } if SupplierTypeCode != "" { where = where + " and SupplierTypeCode = '" + SupplierTypeCode + "'" } if Code != "" { where = where + " and Code like '%" + Code + "%'" } if Name != "" { where = where + " and Name like '%" + Name + "%'" } if Remark != "" { where = where + " and Remark like '%" + Remark + "%'" } if IsDelete != "" { where = where + " and IsDelete like '%" + IsDelete + "%'" } if CreateUserId != "" { where = where + " and CreateUserId like '%" + CreateUserId + "%'" } if CreateBy != "" { where = where + " and CreateBy like '%" + CreateBy + "%'" } if ModifiedOn != "" { where = where + " and ModifiedOn like '%" + ModifiedOn + "%'" } if ModifiedUserId != "" { where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'" } if ModifiedBy != "" { where = where + " and ModifiedBy like '%" + ModifiedBy + "%'" } if CreateOn != "" { dates := strings.Split(CreateOn, ",") if len(dates) == 2 { minDate := dates[0] maxDate := dates[1] where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'" } } svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) var list []suppliercertsub.OilSupplierCertSub total := svc.GetPagingEntitiesWithoutAccCode(page.CurrentPage, page.Size, orderby, asc, &list, where) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total datainfo.PageIndex = page.CurrentPage datainfo.ItemsPerPage = page.Size this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取字典列表 // @Description get user by token // @Success 200 {object} map[string]interface{} // @router /dictlist [get] func (this *OilSupplierCertSubController) GetDictList() { dictList := make(map[string]interface{}) //dictSvc := items.GetItemsService(utils.DBE) userSvc := baseUser.GetBaseUserService(utils.DBE) //customerSvc := svccustomer.GetCustomerService(utils.DBE) //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", 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 var datainfo DataInfo datainfo.Items = dictList this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取实体 // @Description 获取实体 // @Success 200 {object} suppliercertsub.OilSupplierCertSub // @router /get/:id [get] func (this *OilSupplierCertSubController) GetEntity() { Id := this.Ctx.Input.Param(":id") var model suppliercertsub.OilSupplierCertSub svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) svc.GetEntityByIdBytbl(OilSupplierCertSubName, Id, &model) this.Data["json"] = &model this.ServeJSON() } // @Title 添加 // @Description 新增 // @Success 200 {object} controllers.Request // @router /add [post] func (this *OilSupplierCertSubController) AddEntity() { var model suppliercertsub.OilSupplierCertSub var jsonBlob = this.Ctx.Input.RequestBody svc := suppliercertsub.GetOilSupplierCertSubService(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(OilSupplierCertSubName, &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 修改实体 // @Success 200 {object} controllers.Request // @router /update/:id [post] func (this *OilSupplierCertSubController) 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 suppliercertsub.OilSupplierCertSub svc := suppliercertsub.GetOilSupplierCertSubService(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", "SupplierId", "SupplierCertId", "SubClassId", "Code", "Name", "Remark", "IsDelete", "CreateOn", "CreateUserId", "CreateBy", "ModifiedOn", "ModifiedUserId", "ModifiedBy", } err := svc.UpdateEntityBytbl(OilSupplierCertSubName, 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 *OilSupplierCertSubController) 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 suppliercertsub.OilSupplierCertSub var entityempty suppliercertsub.OilSupplierCertSub svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) opdesc := "删除-" + Id err := svc.DeleteOperationAndWriteLogBytbl(OilSupplierCertSubName, 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} controllers.Request // @router /addbusiness [post] func (this *OilSupplierCertSubController) AddBusiness() { var model suppliercertsub.OilSupplierCertSub var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) model.CreateBy = this.User.Realname model.CreateUserId, _ = utils.StrTo(this.User.Id).Int() svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) _, err := svc.InsertEntityBytbl(OilSupplierCertSubName, &model) filesvc := supplierfile.GetSupplierfileService(utils.DBE) var needList []supplierfile.FileList if model.SupplierTypeCode == "01" { needList = filesvc.GetGoodsNeedFileList(model.SubClassId) } else if model.SupplierTypeCode == "02" { needList = filesvc.GetBasicNeedFileList(model.SubClassId) } else { needList = filesvc.GetTechNeedFileList(model.SubClassId) } if err == nil { var list []supplierfile.OilSupplierFile where := "SupplierId = '" + strconv.Itoa(model.SupplierId) + "'" //where += " and SupplierCertId = '" + strconv.Itoa(model.SupplierCertId) + "'" svc.GetEntitysByWhere(OilSupplierFileName, where, &list) if len(list) == 0 { //第一次添加准入项,将共有必备资质写入文件表 for i := 0; i < len(needList); i++ { var entity supplierfile.OilSupplierFile entity.SupplierId = model.SupplierId if i < 4 { entity.SupplierTypeCode = "000" } else { entity.SupplierTypeCode = model.SupplierTypeCode } entity.NeedFileType = needList[i].FileName entity.FileType = 1 entity.EffectDate = time.Now() entity.CreateBy = this.User.Realname entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int() svc.InsertEntityBytbl(OilSupplierFileName, &entity) } } else { if len(needList) > 4 { for i := 4; i < len(needList); i++ { var entity supplierfile.OilSupplierFile entity.SupplierId = model.SupplierId entity.SupplierTypeCode = model.SupplierTypeCode entity.NeedFileType = needList[i].FileName entity.FileType = 1 entity.EffectDate = time.Now() entity.CreateBy = this.User.Realname entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int() svc.InsertEntityBytbl(OilSupplierFileName, &entity) } } } } 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 id path string true // @Success 200 {object} // @router /editbusiness/:id [put] func (this *OilSupplierCertSubController) EditBusiness() { 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 suppliercertsub.OilSupplierCertSub var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) var entity suppliercertsub.OilSupplierCertSub model.ModifiedBy = this.User.Realname model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) opdesc := "编辑准入范围-" + model.Name var cols []string = []string{"SubClassId", "Name", "Code", "Remark", "IsDelete", "ModifiedBy", "ModifiedUserId"} err := svc.UpdateOperationAndWriteLogBytbl(OilSupplierCertSubName, BaseOperationLogName, id, &model, &entity, cols, 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} ErrorInfo // @Failure 403 :id 为空 // @router /businessdelete/:Id [delete] func (this *OilSupplierCertSubController) BusinessDelete() { Id := this.Ctx.Input.Param(":Id") var errinfo ErrorInfo if Id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } where := " Id= " + Id svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) err := svc.DeleteEntityBytbl(OilSupplierCertSubName, where) 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 get user by token // @Success 200 {object} models.Userblood // @router /auditbuslist [get] func (this *OilSupplierCertSubController) AuditbusList() { var list []suppliercertsub.OilSupplierCertSub //获取分页信息 page := this.GetPageInfoForm() svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) orderby := "CreateOn desc" Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = Prop + " " + Order } where := "1 = 1" SupplierCertId := this.GetString("SupplierCertId") if SupplierCertId != "" { where = where + " and a.SupplierCertId = '" + SupplierCertId + "'" } total, list := svc.GetWaitAuditBusinesslist(page.CurrentPage, page.Size, orderby, OilSupplierCertSubName, OilClassOrgSettingName, where) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取审核意见列表 // @Description 获取审核意见列表 // @Success 200 {object} controllers.Request // @router /opinionlist [get] func (this *OilSupplierCertSubController) OpinionList() { SupplierCertSubId := this.GetString("SupplierCertSubId") var list []suppliercertsub.OilSupplierOpinion where := " 1 = 1 " if SupplierCertSubId != "" { where = where + " and SupplierCertSubId = '" + SupplierCertSubId + "'" } svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) svc.GetEntitysByWhere(OilSupplierOpinionName, where, &list) var datainfo DataInfo datainfo.Items = list this.Data["json"] = &datainfo this.ServeJSON() } // @Title 新增审核意见 // @Description 新增审核意见 // @Success 200 {object} controllers.Request // @router /addopinion [post] func (this *OilSupplierCertSubController) AddOpinion() { var model suppliercertsub.OilSupplierOpinion var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) model.AuditorName = this.User.Realname model.AuditorId, _ = utils.StrTo(this.User.Id).Int() model.CreateBy = this.User.Realname model.CreateUserId, _ = utils.StrTo(this.User.Id).Int() svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) where := "SupplierCertSubId=" + strconv.Itoa(model.SupplierCertSubId) + " and AuditorId= " + strconv.Itoa(model.AuditorId) + " and Status = '" + model.Status + "'" svc.DeleteEntityBytbl(OilSupplierOpinionName, where) _, err := svc.InsertEntityBytbl(OilSupplierOpinionName, &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() } }