package oilsupplier import ( "encoding/json" "strings" "time" "dashoo.cn/backend/api/business/oilsupplier/suppliercertappend" . "dashoo.cn/backend/api/controllers" "dashoo.cn/utils" ) type OilSupplierCertAppendController struct { BaseController } // @Title 获取列表 // @Description 获取列表 // @Success 200 {object} []suppliercertappend.OilSupplierCertAppend // @router /list [get] func (this *OilSupplierCertAppendController) GetList() { //获取分页信息 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 } } ApplyDate := this.GetString("ApplyDate") RecUnitId := this.GetString("RecUnitId") RecUnitName := this.GetString("RecUnitName") WorkRange := this.GetString("WorkRange") DenyReason := this.GetString("DenyReason") AuditDate := this.GetString("AuditDate") Remark := this.GetString("Remark") CreateOn := this.GetString("CreateOn") if ApplyDate != "" { where = where + " and ApplyDate like '%" + ApplyDate + "%'" } if RecUnitId != "" { where = where + " and RecUnitId like '%" + RecUnitId + "%'" } if RecUnitName != "" { where = where + " and RecUnitName like '%" + RecUnitName + "%'" } if WorkRange != "" { where = where + " and WorkRange like '%" + WorkRange + "%'" } if DenyReason != "" { where = where + " and DenyReason like '%" + DenyReason + "%'" } if AuditDate != "" { where = where + " and AuditDate like '%" + AuditDate + "%'" } if Remark != "" { where = where + " and Remark like '%" + Remark + "%'" } 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 := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) var list []suppliercertappend.OilSupplierCertAppend total := svc.GetPagingEntitiesWithOrderBytbl("", 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 通过Id获取信息 // @Description get user by token // @Success 200 {object} []suppliercertappend.OilSupplierCertAppend // @router /getEntityById/:id [get] func (this *OilSupplierCertAppendController) GetEntityById() { Id := this.Ctx.Input.Param(":id") var model suppliercertappend.OilSupplierCertAppend svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) svc.GetEntityByIdBytbl(OilSupplierCertAppendName, Id, &model) this.Data["json"] = &model this.ServeJSON() } // @Title 添加 // @Description 添加增项信息 // @Success 200 {object} controllers.Request // @router /addappend [post] func (this *OilSupplierCertAppendController) AddAppend() { var model suppliercertappend.OilSupplierCertAppend var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) model.ApplyDate = time.Now() //申请日期 model.CreateOn = time.Now() model.CreateBy = this.User.Realname model.CreateUserId, _ = utils.StrTo(this.User.Id).Int() svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) _, err := svc.InsertEntityBytbl(OilSupplierCertAppendName, &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 // @Success 200 {object} controllers.Request // @router /update/:id [post] func (this *OilSupplierCertAppendController) UpdateEntity() { var errinfo ErrorInfo var model suppliercertappend.OilSupplierCertAppend id := this.Ctx.Input.Param(":id") if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &model) model.ApplyDate = time.Now() //更新申请日期 model.ModifiedOn = time.Now() model.ModifiedBy = this.User.Realname model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() cols := []string{ "Id", "ApplyDate", "RecUnitId", "RecUnitName", "WorkRange", "Remark", "ModifiedOn", "ModifiedUserId", "ModifiedBy", } err := svc.UpdateEntityBytbl(OilSupplierCertAppendName, 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 *OilSupplierCertAppendController) 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 suppliercertappend.OilSupplierCertAppend var entityempty suppliercertappend.OilSupplierCertAppend svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) opdesc := "删除-" + Id err := svc.DeleteOperationAndWriteLogBytbl(OilSupplierCertAppendName, 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() } }