package oilsupplier import ( "dashoo.cn/backend/api/business/audithistory" "dashoo.cn/backend/api/business/auditsetting" "dashoo.cn/backend/api/business/oilsupplier/infochange" "dashoo.cn/backend/api/business/oilsupplier/supplier" "dashoo.cn/backend/api/business/oilsupplier/suppliercert" "dashoo.cn/backend/api/business/oilsupplier/supplierfile" "dashoo.cn/backend/api/business/register" "dashoo.cn/business2/parameter" "dashoo.cn/business2/permission" "dashoo.cn/business2/userRole" "encoding/json" "fmt" "reflect" "strconv" "strings" "time" "dashoo.cn/backend/api/business/oilsupplier/annualaudit" "dashoo.cn/backend/api/business/workflow" . "dashoo.cn/backend/api/controllers" "dashoo.cn/utils" ) type InfoChangeController struct { BaseController } type InfoShenHeModel struct { InfoId int SuccessStatus int AuditorRemark string SuppId int } type InfoChangeItemsAll struct { InfochangeForm []infoitems SupplierId string MInfoId string } type infoitems struct { SelectItem string SelectItemName string BeChangeInfo string ChangeInfo string } // @Title 获取实体 // @Description 获取实体 // @Success 200 {object} annualaudit.OilAnnualAudit // @router /get/:id [get] func (this *InfoChangeController) GetEntity() { CertId := this.Ctx.Input.Param(":id") var model []infochange.OilInfoChangeItem svc := infochange.GetInfoChangeService(utils.DBE) where := " SupplierId = " + CertId svc.GetEntitysByWhere(OilInfoChangeItemName, where, &model) var datainfo DataInfo datainfo.Items = model this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取实体 // @Description 获取实体 // @Success 200 {object} annualaudit.OilAnnualAudit // @router /getmain/:id [get] func (this *InfoChangeController) GetMainEntity() { Id := this.Ctx.Input.Param(":id") var model []infochange.OilInfoChange svc := infochange.GetInfoChangeService(utils.DBE) where := " Id = " + Id svc.GetEntitysByWhere(OilInfoChangeName, where, &model) var datainfo DataInfo datainfo.Items = model this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取实体 // @Description 获取实体 // @Success 200 {object} annualaudit.OilAnnualAudit // @router /getAccessCardNo/:id [get] func (this *InfoChangeController) GetAccessCardNo() { SuppId := this.Ctx.Input.Param(":id") var model []suppliercert.OilSupplierCert svc := infochange.GetInfoChangeService(utils.DBE) where := " SupplierId = " + SuppId svc.GetEntitysByOrderbyWhere(OilSupplierCertName, where, "SupplierTypeCode asc", &model) var datainfo DataInfo datainfo.Items = model this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取实体 // @Description 获取实体 // @Success 200 {object} annualaudit.OilAnnualAudit // @router /auditget/:id [get] func (this *InfoChangeController) GetEntityThen() { InfoId := this.Ctx.Input.Param(":id") var model []infochange.OilInfoChangeItem svc := infochange.GetInfoChangeService(utils.DBE) where := " InfoId = " + InfoId svc.GetEntitysByWhere(OilInfoChangeItemName, where, &model) var datainfo DataInfo datainfo.Items = model this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取列表 // @Description get user by token // @Success 200 {object} []supplier.OilSupplier // @router /supplist [get] func (this *InfoChangeController) GetSuppList() { //获取分页信息 page := this.GetPageInfoForm() where := " 1=1 " orderby := "b.Id" asc := false Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = Prop if Order == "asc" { asc = true } } SupplierName := this.GetString("SupplierName") OilCertificateNo := this.GetString("OilCertificateNo") Grade := this.GetString("Grade") MgrUnit := this.GetString("MgrUnit") OperType := this.GetString("OperType") Country := this.GetString("Country") MaunAgent := this.GetString("MaunAgent") ConstructTeam := this.GetString("ConstructTeam") CommercialNo := this.GetString("CommercialNo") OrganCode := this.GetString("OrganCode") CountryTaxNo := this.GetString("CountryTaxNo") LocalTaxNo := this.GetString("LocalTaxNo") Address := this.GetString("Address") Province := this.GetString("Province") City := this.GetString("City") Street := this.GetString("Street") HouseNo := this.GetString("HouseNo") ZipCode := this.GetString("ZipCode") QualitySystemCert := this.GetString("QualitySystemCert") ProductQualityCert := this.GetString("ProductQualityCert") MaunLicense := this.GetString("MaunLicense") QualifCert := this.GetString("QualifCert") QualifCertLevel := this.GetString("QualifCertLevel") SafetyLicense := this.GetString("SafetyLicense") TechServiceLic := this.GetString("TechServiceLic") TJInNotify := this.GetString("TJInNotify") SpecIndustryCert := this.GetString("SpecIndustryCert") LegalPerson := this.GetString("LegalPerson") CategoryCode := this.GetString("CategoryCode") CategoryName := this.GetString("CategoryName") RegCapital := this.GetString("RegCapital") Currency := this.GetString("Currency") ContactName := this.GetString("ContactName") CompanyType := this.GetString("CompanyType") SetupTime := this.GetString("SetupTime") DepositBank := this.GetString("DepositBank") BankAccount := this.GetString("BankAccount") EMail := this.GetString("EMail") BankCreditRating := this.GetString("BankCreditRating") Mobile := this.GetString("Mobile") Telphone := this.GetString("Telphone") Fax := this.GetString("Fax") CompanyTel := this.GetString("CompanyTel") QQ := this.GetString("QQ") CompanyUrl := this.GetString("CompanyUrl") SpecSupplier := this.GetString("SpecSupplier") SpecTypeCode := this.GetString("SpecTypeCode") SpecTypeName := this.GetString("SpecTypeName") Remark := this.GetString("Remark") CreateOn := this.GetString("CreateOn") if SupplierName != "" { where = where + " and a.SupplierName like '%" + SupplierName + "%'" } if OilCertificateNo != "" { where = where + " and a.OilCertificateNo like '%" + OilCertificateNo + "%'" } if Grade != "" { where = where + " and a.Grade like '%" + Grade + "%'" } if MgrUnit != "" { where = where + " and a.MgrUnit like '%" + MgrUnit + "%'" } if OperType != "" { where = where + " and a.OperType like '%" + OperType + "%'" } if Country != "" { where = where + " and a.Country like '%" + Country + "%'" } if MaunAgent != "" { where = where + " and a.MaunAgent like '%" + MaunAgent + "%'" } if ConstructTeam != "" { where = where + " and a.ConstructTeam like '%" + ConstructTeam + "%'" } if CommercialNo != "" { where = where + " and a.CommercialNo like '%" + CommercialNo + "%'" } if OrganCode != "" { where = where + " and a.OrganCode like '%" + OrganCode + "%'" } if CountryTaxNo != "" { where = where + " and a.CountryTaxNo like '%" + CountryTaxNo + "%'" } if LocalTaxNo != "" { where = where + " and a.LocalTaxNo like '%" + LocalTaxNo + "%'" } if Address != "" { where = where + " and a.Address like '%" + Address + "%'" } if Province != "" { where = where + " and a.Province like '%" + Province + "%'" } if City != "" { where = where + " and a.City like '%" + City + "%'" } if Street != "" { where = where + " and a.Street like '%" + Street + "%'" } if HouseNo != "" { where = where + " and a.HouseNo like '%" + HouseNo + "%'" } if ZipCode != "" { where = where + " and a.ZipCode like '%" + ZipCode + "%'" } if QualitySystemCert != "" { where = where + " and a.QualitySystemCert like '%" + QualitySystemCert + "%'" } if ProductQualityCert != "" { where = where + " and a.ProductQualityCert like '%" + ProductQualityCert + "%'" } if MaunLicense != "" { where = where + " and a.MaunLicense like '%" + MaunLicense + "%'" } if QualifCert != "" { where = where + " and a.QualifCert like '%" + QualifCert + "%'" } if QualifCertLevel != "" { where = where + " and a.QualifCertLevel like '%" + QualifCertLevel + "%'" } if SafetyLicense != "" { where = where + " and a.SafetyLicense like '%" + SafetyLicense + "%'" } if TechServiceLic != "" { where = where + " and a.TechServiceLic like '%" + TechServiceLic + "%'" } if TJInNotify != "" { where = where + " and a.TJInNotify like '%" + TJInNotify + "%'" } if SpecIndustryCert != "" { where = where + " and a.SpecIndustryCert like '%" + SpecIndustryCert + "%'" } if LegalPerson != "" { where = where + " and a.LegalPerson like '%" + LegalPerson + "%'" } if CategoryCode != "" { where = where + " and a.CategoryCode like '%" + CategoryCode + "%'" } if CategoryName != "" { where = where + " and a.CategoryName like '%" + CategoryName + "%'" } if RegCapital != "" { where = where + " and a.RegCapital like '%" + RegCapital + "%'" } if Currency != "" { where = where + " and a.Currency like '%" + Currency + "%'" } if ContactName != "" { where = where + " and a.ContactName like '%" + ContactName + "%'" } if CompanyType != "" { where = where + " and a.CompanyType like '%" + CompanyType + "%'" } if SetupTime != "" { where = where + " and a.SetupTime like '%" + SetupTime + "%'" } if DepositBank != "" { where = where + " and a.DepositBank like '%" + DepositBank + "%'" } if BankAccount != "" { where = where + " and a.BankAccount like '%" + BankAccount + "%'" } if EMail != "" { where = where + " and a.EMail like '%" + EMail + "%'" } if BankCreditRating != "" { where = where + " and a.BankCreditRating like '%" + BankCreditRating + "%'" } if Mobile != "" { where = where + " and a.Mobile like '%" + Mobile + "%'" } if Telphone != "" { where = where + " and a.Telphone like '%" + Telphone + "%'" } if Fax != "" { where = where + " and a.Fax like '%" + Fax + "%'" } if CompanyTel != "" { where = where + " and a.CompanyTel like '%" + CompanyTel + "%'" } if QQ != "" { where = where + " and a.QQ like '%" + QQ + "%'" } if CompanyUrl != "" { where = where + " and a.CompanyUrl like '%" + CompanyUrl + "%'" } if SpecSupplier != "" { where = where + " and a.SpecSupplier like '%" + SpecSupplier + "%'" } if SpecTypeCode != "" { where = where + " and a.SpecTypeCode like '%" + SpecTypeCode + "%'" } if SpecTypeName != "" { where = where + " and a.SpecTypeName like '%" + SpecTypeName + "%'" } if Remark != "" { where = where + " and a.Remark like '%" + Remark + "%'" } if CreateOn != "" { dates := strings.Split(CreateOn, ",") if len(dates) == 2 { minDate := dates[0] maxDate := dates[1] where = where + " and a.CreateOn>='" + minDate + "' and a.CreateOn<='" + maxDate + "'" } } svc := infochange.GetInfoChangeService(utils.DBE) var registerUser register.OilCorporateInfo sql := " UserName='" + this.User.Username + "'" svc.GetEntity(®isterUser, sql) //企业用户必须加创建人条件 if this.User.IsCompanyUser == 1 { where = where + " and (b.CreateUserId = '" + this.User.Id + "' or a.CommercialNo='" + registerUser.CommercialNo + "')" } else { //超级管理员和有查看所有数据权限的用户不加条件 svcPerm := permission.GetPermissionService(utils.DBE) isauth := svcPerm.IsAuthorized(this.User.Id, "oil_supplier.marketAccess.AllRecord") if !svcPerm.IsAdmin(this.User.Id) && !isauth { where = where + " and (b.CreateUserId = '" + this.User.Id + "' or a.CommercialNo='" + registerUser.CommercialNo + "')" } } var list []infochange.SuppModelInfo total := svc.GetSuppPagingEntitiesWithOrderBytbl(OilSupplierName, OilInfoChangeName, page.CurrentPage, page.Size, orderby, asc, &list, where) //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 获取列表 // @Description get user by token // @Success 200 {object} []infochange.OilInfoChange // @router /alllist [get] func (this *InfoChangeController) GetAllEntityList() { //获取分页信息 page := this.GetPageInfoForm() where := " 1=1 and b.OldSupplierName is not null" orderby := "a.Id" asc := false Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = "a." + Prop if Order == "asc" { asc = true } } SupplierName := this.GetString("SupplierName") if SupplierName != "" { where = where + " and a.SupplierName like '%" + SupplierName + "%'" } svc := infochange.GetInfoChangeService(utils.DBE) var list []infochange.OilUsedName total := svc.GetUsedNameWithOrderBytbl(OilSupplierName, OilInfoChangeName, page.CurrentPage, page.Size, orderby, asc, &list, where) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取列表 // @Description get user by token // @Success 200 {object} []infochange.OilInfoChange // @router /list [get] func (this *InfoChangeController) 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 } } SupplierTypeName := this.GetString("SupplierTypeName") RecUnitId := this.GetString("RecUnitId") AccessCardNo := this.GetString("AccessCardNo") SupplierName := this.GetString("SupplierName") CreateOn := this.GetString("CreateOn") if SupplierTypeName != "" { where = where + " and SupplierTypeName like '%" + SupplierTypeName + "%'" } if RecUnitId != "" { where = where + " and RecUnitId like '%" + RecUnitId + "%'" } if AccessCardNo != "" { where = where + " and AccessCardNo like '%" + AccessCardNo + "%'" } if SupplierName != "" { where = where + " and SupplierName like '%" + SupplierName + "%'" } if CreateOn != "" { dates := strings.Split(CreateOn, ",") if len(dates) == 2 { minDate := dates[0] maxDate := dates[1] where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'" } } //找出待办任务 actisvc := workflow.GetActivitiService(utils.DBE) certIdList := actisvc.GetMyTasks(workflow.OIL_INFO_CHANGE, this.User.Id) appendIdarr := strings.Split(certIdList, ",") for i, item := range appendIdarr { idx := strings.Index(item, "-") if idx >= 0 { appendIdarr[i] = strings.Split(item, "-")[0] } } certIdList = strings.Join(appendIdarr, ",") svc := infochange.GetInfoChangeService(utils.DBE) var list []infochange.OilInfoChange var total int64 = 0 if certIdList != "" { where += " and Id in (" + certIdList + ")" 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 获取实体 // @Description 获取实体 // @Success 200 {object} annualaudit.OilAnnualAudit // @router /getinfoforitem [get] func (this *InfoChangeController) GetInfoForItem() { certId := this.GetString("certId") selctitem := this.GetString("selctitem") svc := infochange.GetInfoChangeService(utils.DBE) where := "Id =" + utils.ToStr(certId) var selecteditem = svc.GetInfoforItem(""+OilSupplierName, selctitem, where) this.Data["json"] = &selecteditem this.ServeJSON() } // @Title 获取实体 // @Description 获取实体 // @Success 200 {object} supplier.OilSupplier // @router /getchangelist/:id [get] func (this *InfoChangeController) GetChangeEntity() { Id := this.Ctx.Input.Param(":id") InfoId := this.GetString("InfomainId") var models [2]supplier.OilSupplier var model supplier.OilSupplier var enumModel supplier.OilSupplier svc := supplier.GetOilSupplierService(utils.DBE) svc.GetEntityByIdBytbl(OilSupplierName, Id, &model) models[0] = model var infoitems []infochange.OilInfoChangeItem where := " SupplierId = " + Id +" and InfoId ="+InfoId where = where + " and ChangeStatus = 0" svc.GetEntitysByWhere(OilInfoChangeItemName, where, &infoitems) tmpModel := &model enumModel = *tmpModel immumodel := reflect.ValueOf(&enumModel) elem := immumodel.Elem() if len(infoitems) == 0 { models[1] = enumModel this.Data["json"] = &models this.ServeJSON() return } else { for _, info := range infoitems { fmt.Println(info.SelectItem) fmt.Println(";;;;;;;;;", elem.FieldByName(info.SelectItem).Type().String()) if elem.FieldByName(info.SelectItem).Type().String() == "int64" { intchangeinfo, _ := strconv.ParseInt(info.ChangeInfo, 10, 64) elem.FieldByName(info.SelectItem).SetInt(intchangeinfo) } else if elem.FieldByName(info.SelectItem).Type().String() == "float64" { floatchangeinfo, _ := strconv.ParseFloat(info.ChangeInfo, 64) elem.FieldByName(info.SelectItem).SetFloat(floatchangeinfo) } else if elem.FieldByName(info.SelectItem).Type().String() == "time.Time" { t, _ := time.Parse("2006-01-02", info.ChangeInfo) elem.FieldByName(info.SelectItem).Set(reflect.ValueOf(t)) } else { elem.FieldByName(info.SelectItem).SetString(info.ChangeInfo) } } models[1] = enumModel this.Data["json"] = &models this.ServeJSON() } } // @Title 获取列表 // @Description get user by token // @Success 200 {object} []annualaudit.OilAnnualAudit // @router /mytasks [get] func (this *InfoChangeController) GetMyTaskEntityList() { //获取分页信息 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 } } SupplierTypeName := this.GetString("SupplierTypeName") RecUnitId := this.GetString("RecUnitId") AccessCardNo := this.GetString("AccessCardNo") SupplierName := this.GetString("SupplierName") CreateOn := this.GetString("CreateOn") if SupplierTypeName != "" { where = where + " and SupplierTypeName like '%" + SupplierTypeName + "%'" } if RecUnitId != "" { where = where + " and RecUnitId like '%" + RecUnitId + "%'" } if AccessCardNo != "" { where = where + " and AccessCardNo like '%" + AccessCardNo + "%'" } if SupplierName != "" { where = where + " and SupplierName like '%" + SupplierName + "%'" } 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 := annualaudit.GetOilAnnualAuditService(utils.DBE) var list []annualaudit.OilAnnualAudit //找出待办任务 actisvc := workflow.GetActivitiService(utils.DBE) certIdList := actisvc.GetMyTasks(workflow.OIL_AUDIT_APPLY, this.User.Id) where += " and Id in (" + certIdList + ")" where += " and Status != -2 " //根据部门查询待办任务 total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where) //total := svc.GetMyPagingEntitiesWithOrderBytbl(OilSupplierName, OilSupplierCertName, 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 // @Success 200 {object} ErrorInfo // @Failure 403 :id 为空 // @router /delete/:Id [delete] func (this *InfoChangeController) 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 infochange.OilInfoChangeItem var entityempty infochange.OilInfoChangeItem svc := infochange.GetInfoChangeService(utils.DBE) opdesc := "删除-" + Id err := svc.DeleteOperationAndWriteLogBytbl(""+OilInfoChangeItemName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "信息变更") 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 /addinfochangeitem [post] func (this *InfoChangeController) AddInfoChangeItem() { var model infochange.OilInfoChangeItem var jsonBlob = this.Ctx.Input.RequestBody svc := infochange.GetInfoChangeService(utils.DBE) json.Unmarshal(jsonBlob, &model) model.CreateOn = time.Now() model.CreateBy = this.User.Realname model.CreateUserId, _ = utils.StrTo(this.User.Id).Int() _, err := svc.InsertEntityBytbl(""+OilInfoChangeItemName, &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 /addinfochangeitemch [post] func (this *InfoChangeController) AddInfoChangeItemCh() { var model InfoChangeItemsAll var jsonBlob = this.Ctx.Input.RequestBody svc := infochange.GetInfoChangeService(utils.DBE) json.Unmarshal(jsonBlob, &model) var err error where := " SupplierId = " + model.SupplierId where = where + " and InfoId = " + model.MInfoId var deleteEntity infochange.OilInfoChangeItem delMainId, _ := strconv.Atoi(model.MInfoId) deleteEntity.InfoId = delMainId svc.DBE.Delete(deleteEntity) var infoitementitys []infochange.OilInfoChangeItem for i := 0; i < len(model.InfochangeForm); i++ { var infoitementity infochange.OilInfoChangeItem infoitementity.SelectItem = model.InfochangeForm[i].SelectItem infoitementity.SelectItemName = model.InfochangeForm[i].SelectItemName infoitementity.ChangeInfo = model.InfochangeForm[i].ChangeInfo infoitementity.BeChangeInfo = model.InfochangeForm[i].BeChangeInfo infoitementity.ChangeStatus = 0 infoitementity.SupplierId, _ = strconv.Atoi(model.SupplierId) infoitementity.InfoId, _ = strconv.Atoi(model.MInfoId) infoitementity.CreateOn = time.Now() infoitementity.CreateBy = this.User.Realname infoitementity.CreateUserId, _ = utils.StrTo(this.User.Id).Int() infoitementitys = append(infoitementitys, infoitementity) } _, err = svc.InsertEntityBytbl(""+OilInfoChangeItemName, &infoitementitys) 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 获取二级初审人员 // @router /getauditerbydept/:deptId [get] func (this *InfoChangeController) GetAuditerByDept() { Id := this.Ctx.Input.Param(":deptId") //var auditWorkflow auditsetting.Base_OilAuditSetting rsvc := auditsetting.GetOilAuditSettingService(utils.DBE) //rsvc.GetAuditStepRoleEntity(OilAuditSettingName, Id, workflow.FIRST_TRIAL, &auditWorkflow) var userlist []userRole.Base_User where := " CompanyId = " + Id rsvc.GetEntities(&userlist, where) var datainfo ErrorDataInfo datainfo.Item = userlist this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取企业法规处人员 // @Description 获取企业法规处人员 // @router /getauditer [get] func (this *InfoChangeController) GetAuditer() { //svc := infochange.GetInfoChangeService(utils.DBE) //certSrv := suppliercert.GetOilSupplierCertService(utils.DBE) var userlist []userRole.Base_User var setting auditsetting.Base_OilAuditSetting svc := userRole.GetUserService(utils.DBE) where := "AuditStepCode='" + workflow.PROF_REGULATION + "'" svc.GetEntity(&setting, where) paramSvc := baseparameter.GetBaseparameterService(utils.DBE) topid := paramSvc.GetBaseparameterMessage("", "paramset", "CENT_AUDIT") ids := svc.GetUserIdsByRoleId(strconv.Itoa(setting.RoleId)) tempstr := strings.Join(ids, ",") userIds := strings.Replace(tempstr, "uid_", "", -1) userIds = strings.Trim(userIds, ",") if userIds != "" { where := "Id in (" + userIds + ")" + "and UnitId=" + topid svc.GetEntities(&userlist, where) } //var users []userRole.Base_RoleList //certSrv.GetAuditUser("100000178", workflow.PROF_REGULATION, &users) //var users []suppliercert.UserList // where := "OrganizeId=100000178 and AuditStepCode='" + workflow.PROF_REGULATION + "'" //svc.GetEntitysByWhere(OilAuditSettingName, where, &users) var datainfo ErrorDataInfo datainfo.Item = userlist this.Data["json"] = &datainfo this.ServeJSON() } // @Title 添加 // @Description 新增信息变更 // @Success 200 {object} controllers.Request // @router /addinfomain [post] func (this *InfoChangeController) AddInfoMain() { SupplierId := this.GetString("SupplierId") Remark := this.GetString("Remark") var infochmain infochange.OilInfoChange var infochm []infochange.OilInfoChange var suppliermodel supplier.OilSupplier var errinfo ErrorDataInfo svc := infochange.GetInfoChangeService(utils.DBE) where := " SupplierId = " + SupplierId + " and Status < 4" svc.GetEntitysByWhere(OilInfoChangeName, where, &infochm) if len(infochm) > 0 { errinfo.Message = "有已提交在申请中的信息变更,请审批完成后再提交!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } svc.GetEntityById(SupplierId, &suppliermodel) infochmain.Status = "0" infochmain.SupplierName = suppliermodel.SupplierName infochmain.OldSupplierName = suppliermodel.SupplierName infochmain.PACNumber = suppliermodel.PACNumber infochmain.SupplierCertificate = suppliermodel.SupplierCertificate infochmain.MgrUnit = suppliermodel.MgrUnit infochmain.OilCertificateNo = suppliermodel.OilCertificateNo infochmain.OperType = suppliermodel.OperType infochmain.Country = suppliermodel.Country infochmain.MaunAgent = suppliermodel.MaunAgent infochmain.CommercialNo = suppliermodel.CommercialNo infochmain.OrganCode = suppliermodel.OrganCode infochmain.SupplierId, _ = strconv.Atoi(SupplierId) infochmain.Remark = Remark infochmain.CreateOn = time.Now() infochmain.CreateBy = this.User.Realname infochmain.CreateUserId, _ = utils.StrTo(this.User.Id).Int() _, err := svc.InsertEntityBytbl(OilInfoChangeName, &infochmain) if err == nil { errinfo.Message = "添加成功!" errinfo.Code = 0 errinfo.Item = infochmain.Id this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "添加失败!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 获取信息变更企业名称 // @Description 获取实体 // @Success 200 {object} // @router /addsupplierlist [get] func (this *InfoChangeController) GetAddSupplierList() { svc := infochange.GetInfoChangeService(utils.DBE) var supplierlist []annualaudit.Suppliername where := "1=1" //企业用户必须加创建人条件 if this.User.IsCompanyUser == 1 { where = where + " and a.CreateUserId = '" + this.User.Id + "'" } else { //超级管理员和有查看所有数据权限的用户不加条件 svcPerm := permission.GetPermissionService(utils.DBE) isauth := svcPerm.IsAuthorized(this.User.Id, "oil_supplier.marketAccess.AllRecord") if !svcPerm.IsAdmin(this.User.Id) && !isauth { where = where + " and a.CreateUserId = '" + this.User.Id + "'" } } supplierlist = svc.GetSupplierList(""+OilSupplierName, where) var datainfo DataInfo datainfo.Items = supplierlist this.Data["json"] = &datainfo this.ServeJSON() } // @Title 提交审批 // @Description 提交审批 // @Success 200 {object} controllers.Request // @router /commitaudit/:id [post] func (this *InfoChangeController) CommitAuditEntity() { //suppId := this.Ctx.Input.Param(":id") firstAudit := this.GetString("auditer") fushenauditer := this.GetString("fushenauditer") Remark := this.GetString("Remark") InfoId := this.GetString("MInfoId") //取出审批列表 svc := infochange.GetInfoChangeService(utils.DBE) var infochangeentity infochange.OilInfoChange infwhere := " Id = " + InfoId svc.GetEntity(&infochangeentity, infwhere) var errinfo ErrorDataInfo defer func() { //finally处理失败的异常 if err := recover(); err != nil { errinfo.Message = "提交失败," + err.(string) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } else { //返回正确结果 errinfo.Message = "审核提交成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } }() svcActiviti := workflow.GetActivitiService(utils.DBE) processInstanceId := "" businessKey := "" businessKey = InfoId + "-" + strconv.Itoa(infochangeentity.AuditIndex) processInstanceId = svcActiviti.StartProcess(workflow.OIL_INFO_CHANGE, businessKey, this.User.Id) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_INFO_CHANGE ActiComplete.BusinessKey = businessKey ActiComplete.UserNames = firstAudit ActiComplete.UserId = this.User.Id ActiComplete.Result = "1" ActiComplete.Remarks = Remark ActiComplete.CallbackUrl = "" receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal == "true" { errinfo.Message = "提交成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "工作流异常,请联系管理员!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } //记下workflowID(首次提交时才会记录,中间状态请忽略) 及审批状态 infochangeentity.WorkFlowId = processInstanceId infochangeentity.Status = suppliercert.FIRST_TRIAL_STATUS //二级单位初审 infochangeentity.FirstAudit, _ = strconv.Atoi(firstAudit) infochangeentity.SecondAudit, _ = strconv.Atoi(fushenauditer) infochangeentity.AuditIndex = infochangeentity.AuditIndex + 1 infochangeentity.BusinessKey = ActiComplete.BusinessKey infochangeentity.CreateOn = time.Now() infochangeentity.CreateBy = this.User.Realname infochangeentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int() cols := []string{ "Id", "WorkflowId", "Status", "Step", "FirstAudit", "SecondAudit", "AuditIndex", "BusinessKey", "CreateOn", "CreateBy", "CreateUserId", } svc.UpdateEntityByIdCols(InfoId, infochangeentity, cols) } // @Title 提交审批 // @Description 提交审批 // @Success 200 {object} controllers.Request // @router /audit/:id [post] func (this *InfoChangeController) AuditEntity() { suppId := this.Ctx.Input.Param(":id") firstAudit := this.GetString("auditer") Remark := this.GetString("Remark") InfoId := this.GetString("MInfoId") //取出审批列表 svc := infochange.GetInfoChangeService(utils.DBE) var infoitems []infochange.OilInfoChangeItem where := " SupplierId = " + suppId svc.GetEntities(&infoitems, where) var infochangeentity infochange.OilInfoChange infwhere := " Id = " + InfoId svc.GetEntity(&infochangeentity, infwhere) var infomodel infochange.OilInfoChangeItem var errinfo ErrorDataInfo defer func() { //finally处理失败的异常 if err := recover(); err != nil { errinfo.Message = "提交失败," + err.(string) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } else { //返回正确结果 errinfo.Message = "审核提交成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } }() var items string for i := 0; i < len(infoitems); i++ { items = fmt.Sprintf("%s %s %s %s", items, infoitems[i].SelectItem, ","+infoitems[i].BeChangeInfo, ","+infoitems[i].ChangeInfo+";") } items = strings.Trim(items, ";") infowhere := " Id = " + InfoId svc.Updateentityinfo(OilInfoChangeName, items, infowhere) //修改从表infoid for i := 0; i < len(infoitems); i++ { infomodel.InfoId, _ = strconv.Atoi(InfoId) err := svc.UpdateEntityBytbl(OilInfoChangeItemName, infoitems[i].Id, &infomodel, []string{"InfoId"}) fmt.Println(err) } svcActiviti := workflow.GetActivitiService(utils.DBE) processInstanceId := "" businessKey := "" if infochangeentity.WorkFlowId == "0" || len(infochangeentity.WorkFlowId) <= 0 { //启动工作流 businessKey = InfoId + "-" + strconv.Itoa(infochangeentity.AuditIndex) processInstanceId = svcActiviti.StartProcess(workflow.OIL_INFO_CHANGE, businessKey, this.User.Id) } var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_INFO_CHANGE ActiComplete.BusinessKey = businessKey ActiComplete.UserNames = firstAudit ActiComplete.UserId = this.User.Id ActiComplete.Result = "1" ActiComplete.Remarks = Remark ActiComplete.CallbackUrl = "" receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal == "true" { errinfo.Message = "提交成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "工作流异常,请联系管理员!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } //记下workflowID(首次提交时才会记录,中间状态请忽略) 及审批状态 infochangeentity.WorkFlowId = processInstanceId infochangeentity.Status = suppliercert.FIRST_TRIAL_STATUS //二级单位初审 infochangeentity.AuditIndex = infochangeentity.AuditIndex + 1 infochangeentity.BusinessKey = ActiComplete.BusinessKey infochangeentity.CreateOn = time.Now() infochangeentity.CreateBy = this.User.Realname infochangeentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int() cols := []string{ "Id", "WorkflowId", "Status", "Step", "FirstAudit", "AuditIndex", "BusinessKey", "CreateOn", "CreateBy", "CreateUserId", } svc.UpdateEntityByIdCols(InfoId, infochangeentity, cols) } // @Title 审批 // @Description 审批 // @Success 200 {object} controllers.Request // @router /infoaudit [post] func (this *InfoChangeController) InfoAudit() { svc := infochange.GetInfoChangeService(utils.DBE) var jsonblob = this.Ctx.Input.RequestBody var dataother InfoShenHeModel json.Unmarshal(jsonblob, &dataother) //取出审批列表 var infoid = dataother.InfoId var infomodel infochange.OilInfoChange svc.GetEntityById(utils.ToStr(dataother.InfoId), &infomodel) var infoitems []infochange.OilInfoChangeItem where := "SupplierId = " + utils.ToStr(dataother.SuppId) +" and InfoId = " +utils.ToStr(dataother.InfoId) svc.GetEntities(&infoitems, where) var errinfo ErrorDataInfo defer func() { //finally处理失败的异常 if err := recover(); err != nil { errinfo.Message = "提交失败," + err.(string) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } else { //返回正确结果 errinfo.Message = "审核提交成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } }() //审核状态判断进行的操作 step := 2 status := "" backstatus := "0" var userIds string if infomodel.Status == suppliercert.FIRST_TRIAL_STATUS { userIds = utils.ToStr(infomodel.SecondAudit) status = suppliercert.SECOND_TRIAL_STATUS step = 2 backstatus = suppliercert.NOPASS_STATUS } else if infomodel.Status == suppliercert.SECOND_TRIAL_STATUS { status = suppliercert.CENT_AUDIT_STATUS backstatus = suppliercert.NO_SECOND_TRIAL_STATUS step = 2 //dictSvc := items.GetItemsService(utils.DBE) //deptIds := dictSvc.GetKeyValueItems("CENT_AUDIT") //var users []userRole.Base_RoleList //certSrv := suppliercert.GetOilSupplierCertService(utils.DBE) //for _, dept := range deptIds { // certSrv.GetAuditUser(dept.Value, workflow.PROF_REGULATION, &users) // for _, tmpUser := range users { // userIds += strconv.FormatInt(tmpUser.Id, 10) + "," // } //} paramSvc := baseparameter.GetBaseparameterService(utils.DBE) topid := paramSvc.GetBaseparameterMessage("", "paramset", "CENT_AUDIT") var userlist []userRole.Base_User var setting auditsetting.Base_OilAuditSetting usvc := userRole.GetUserService(utils.DBE) where := "AuditStepCode='" + workflow.PROF_REGULATION + "'" svc.GetEntity(&setting, where) ids := usvc.GetUserIdsByRoleId(strconv.Itoa(setting.RoleId)) tempstr := strings.Join(ids, ",") uids := strings.Replace(tempstr, "uid_", "", -1) uids = strings.Trim(uids, ",") if uids != "" { where := "Id in (" + uids + ")" + " and UnitId=" + topid svc.GetEntities(&userlist, where) } for _, tmpUser := range userlist { userIds += strconv.Itoa(tmpUser.Id) + "," } userIds = strings.Trim(userIds, ",") } else if infomodel.Status == suppliercert.CENT_AUDIT_STATUS { status = suppliercert.ALL_PASE_STATUS step = 3 backstatus = suppliercert.NO_THIRD_TRIAL_STATUS } svcActiviti := workflow.GetActivitiService(utils.DBE) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_INFO_CHANGE ActiComplete.BusinessKey = infomodel.BusinessKey ActiComplete.UserNames = userIds ActiComplete.UserId = this.User.Id ActiComplete.Remarks = dataother.AuditorRemark ActiComplete.CallbackUrl = "" var myerr error if dataother.SuccessStatus == 1 { ActiComplete.Result = "1" receiveVal := svcActiviti.TaskComplete(ActiComplete) if infomodel.Status == suppliercert.CENT_AUDIT_STATUS { //信息更新 var infochangeitemmodel infochange.OilInfoChangeItem var supmodel supplier.OilSupplier infochangeitemmodel.ChangeStatus = 1 infomodel.Status = status itemswhere := "InfoId = " + utils.ToStr(infoid) myerr = svc.UpdateEntityBywheretbl(OilInfoChangeItemName, &infochangeitemmodel, []string{"ChangeStatus"}, itemswhere) myerr = this.updatesupplier(OilSupplierName, dataother.SuppId, infoitems, supmodel) //资质更新 where := "SupplierId = " + utils.ToStr(dataother.SuppId) + " and SupType = 2" var supfilemodel supplierfile.OilSupplierFile supfilemodel.SupType = 3 svc.UpdateEntityBywheretbl(OilSupplierFileName, &supfilemodel, []string{"SupType"}, where) //var qualdetail []qualchange.OilQualChangeDetail //svc.UpdateEntityBytbl(OilSupplierFileName, qualdetail[i].FileId, &supfilemodel, []string{"SupType"}) //where := "SupplierId = " + utils.ToStr(dataother.SuppId) //svc.GetEntities(&qualdetail, where) //if len(qualdetail) > 0 { // for i := 0; i < len(qualdetail); i++ { // var supfilemodel supplierfile.OilSupplierFile // supfilemodel.FileName = qualdetail[i].FileName // supfilemodel.FileUrl = qualdetail[i].FileUrl // supfilemodel.EffectDate = qualdetail[i].EffectDate // supfilemodel.SupType = 3 // svc.UpdateEntityBytbl(OilSupplierFileName, qualdetail[i].FileId, &supfilemodel, []string{"FileName", "FileUrl", "EffectDate","SupType"}) // } //} } infomodel.Status = status infomodel.Step = step if receiveVal == "true" { cols := []string{ "Id", "Status", "Step", } _, myerr = svc.UpdateEntityByIdCols(infoid, infomodel, cols) if myerr == nil { errinfo.Message = "提交成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "提交失败!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } else { errinfo.Message = "工作流异常,请联系管理员!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } } else { ActiComplete.Result = "0" receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal == "true" { if infomodel.Status == suppliercert.CENT_AUDIT_STATUS { infomodel.Status = backstatus } else { infomodel.Status = backstatus // 审批历史 var audithistoryentity audithistory.Base_AuditHistory audithistoryentity.EntityId = infoid audithistoryentity.WorkflowId = infomodel.WorkFlowId audithistoryentity.Process = ActiComplete.ProcessKey audithistoryentity.BusinessKey = ActiComplete.BusinessKey audithistoryentity.Type = "04" audithistoryentity.BackStep = infomodel.Status audithistoryentity.Index = infomodel.AuditIndex audithistoryentity.CreateOn = time.Now() audithistoryentity.CreateBy = this.User.Realname audithistoryentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int() _, myerr = svc.InsertEntity(audithistoryentity) infomodel.WorkFlowId = "" } infomodel.Step = 1 cols := []string{ "Status", "Step", } _, myerr := svc.UpdateEntityByIdCols(infoid, infomodel, cols) if myerr == nil { errinfo.Message = "提交成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "提交失败!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } else { errinfo.Message = "工作流异常,请联系管理员!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } } } //更新供方信息表 func (this *InfoChangeController) updatesupplier(supname string, suppid int, infoitems []infochange.OilInfoChangeItem, supmodel supplier.OilSupplier) error { svc := infochange.GetInfoChangeService(utils.DBE) var err error if len(infoitems) > 0 { for i := 0; i < len(infoitems); i++ { //var cols []string //cols = append(cols, infoitems[i].SelectItem) where := " Id = " + utils.ToStr(suppid) var sql string sql = `UPDATE ` + supname + ` set ` + infoitems[i].SelectItem + ` = ` + infoitems[i].ChangeInfo + ` where ` + where _, err = svc.DBE.Exec(sql) //err = svc.UpdateEntityBytbl(OilSupplierName, suppid, &supmodel, cols) } } return err }