package oilsupplier import ( "dashoo.cn/backend/api/business/audithistory" "dashoo.cn/backend/api/business/auditsetting" msg2 "dashoo.cn/backend/api/business/msg" "dashoo.cn/backend/api/business/oilsupplier/infochange" "dashoo.cn/backend/api/business/oilsupplier/oilcostmanage" "dashoo.cn/backend/api/business/oilsupplier/qualchange" "dashoo.cn/backend/api/business/oilsupplier/supplier" "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub" "dashoo.cn/backend/api/business/oilsupplier/supplierfile" "dashoo.cn/backend/api/business/oilsupplier/supplierlog" "dashoo.cn/backend/api/business/oilsupplier/tableheader" "dashoo.cn/backend/api/business/organize" "dashoo.cn/backend/api/business/paymentinfo" "dashoo.cn/backend/api/business/register" "dashoo.cn/business2/parameter" "dashoo.cn/business2/userRole" "dashoo.cn/business3/items" "encoding/json" "fmt" "log" "strconv" "strings" "time" "dashoo.cn/backend/api/business/oilsupplier/suppliercert" "dashoo.cn/backend/api/business/workflow" "dashoo.cn/business2/permission" "dashoo.cn/backend/api/business/oilsupplier/suppliercertappend" "dashoo.cn/backend/api/business/oilsupplier/suppliercertappendsub" . "dashoo.cn/backend/api/controllers" "dashoo.cn/utils" "github.com/go-xorm/xorm" ) type OilSupplierCertAppendController struct { BaseController } type AppShenHeModel struct { AnnualId int SuccessStatus int AuditorRemark string Auditer int MajorDept int } // @Title 获取列表 // @Description 获取列表 // @Success 200 {object} []suppliercertappend.OilSupplierCertAppend // @router /list [get] func (this *OilSupplierCertAppendController) GetList() { //获取分页信息 page := this.GetPageInfoForm() where := " b.Id is not null " orderby := "b.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") AppendType := this.GetString("AppendType") DenyReason := this.GetString("DenyReason") AuditDate := this.GetString("AuditDate") Remark := this.GetString("Remark") CreateOn := this.GetString("CreateOn") if ApplyDate != "" { where = where + " and b.ApplyDate like '%" + ApplyDate + "%'" } if RecUnitId != "" { where = where + " and b.RecUnitId like '%" + RecUnitId + "%'" } if RecUnitName != "" { where = where + " and b.RecUnitName like '%" + RecUnitName + "%'" } if AppendType != "" { where = where + " and b.AppendType like '%" + AppendType + "%'" } if DenyReason != "" { where = where + " and b.DenyReason like '%" + DenyReason + "%'" } if AuditDate != "" { where = where + " and b.AuditDate like '%" + AuditDate + "%'" } if Remark != "" { where = where + " and b.Remark like '%" + Remark + "%'" } if CreateOn != "" { dates := strings.Split(CreateOn, ",") if len(dates) == 2 { minDate := dates[0] maxDate := dates[1] where = where + " and b.CreateOn>='" + minDate + "' and b.CreateOn<='" + maxDate + "'" } } svc := suppliercertappend.GetOilSupplierCertAppendService(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.append.AllRecord") if !svcPerm.IsAdmin(this.User.Id) && !isauth { where = where + " and (b.CreateUserId = '" + this.User.Id + "' or a.CommercialNo='" + registerUser.CommercialNo + "')" } } var list []suppliercertappend.OilSupplierCertAppend //total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where) total := svc.GetMyPagingEntitiesWithOrderBytbl(OilSupplierName, OilSupplierCertAppendName, 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 根据创建用户Id和增项类别号获取公司信息 // @Success 200 {object} []suppliercertappend.OilSupplierCertAppend // @router /getsupplier [get] func (this *OilSupplierCertAppendController) GetSupplier() { SuppTypeCode := this.GetString("SuppTypeCode") svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) where := "1=1 " if SuppTypeCode != "" { where = " WHERE b.Id is NOT NULL AND a.SupplierTypeCode = '" + SuppTypeCode + "' and a.InFlag='1'" } else { where = " WHERE b.Id is NOT NULL AND a.InFlag='1'" } 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 b.CommercialNo='" + registerUser.CommercialNo + "')" //if this.User.IsCompanyUser == 1 { // where = where + " and b.CreateUserId = '" + this.User.Id + "'" } sqlStr := "SELECT b.Id AS SupplierId, a.Id AS SupplierCertId, b.SupplierName AS SupplierName FROM OilSupplierCert AS a LEFT JOIN OilSupplier AS b ON a.SupplierId = b.Id " sqlStr = sqlStr + where model, _ := svc.DBE.QueryString(sqlStr) this.Data["json"] = &model this.ServeJSON() } // @Title 添加 // @Description 添加增项信息 // @Success 200 {object} controllers.Request // @router /addappend [post] func (this *OilSupplierCertAppendController) AddAppend() { var errinfo DataEntryInfo var jsonblob = this.Ctx.Input.RequestBody var cermodel suppliercert.OilSupplierCert var model suppliercertappend.OilSupplierCertAppend json.Unmarshal(jsonblob, &model) where := " Id = " + utils.ToStr(model.SupplierCertId) + " and SupplierTypeCode = '" + model.AppendType + "'" svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) where_app := " SupplierCertId = " + utils.ToStr(model.SupplierCertId) + " and SupplierId = " + utils.ToStr(model.SupplierId) + " and AppendType = '" + model.AppendType + "'" //where_app += " and Status < 11" orderby := "ApplyDate DESC" var modeltmp []suppliercertappend.OilSupplierCertAppend svc.GetEntitysByOrderbyWhere(OilSupplierCertAppendName, where_app, orderby, &modeltmp) if len(modeltmp) > 0 { status, _ := strconv.Atoi(modeltmp[0].Status) if status < 11 && status != 8 { errinfo.Message = "已提交增项申请,审批通过后才可再提交申请!" errinfo.Code = -1 errinfo.Info = model.Id this.Data["json"] = &errinfo this.ServeJSON() return } var cert suppliercert.OilSupplierCert svc.GetEntityById(model.SupplierCertId, &cert) if cert.IsRestrict == 1 { paramSvc := baseparameter.GetBaseparameterService(utils.DBE) sAddLimitMonth, _ := strconv.Atoi(paramSvc.GetBaseparameterMessage("GFGL1", "paramset", "sAddLimitMonth")) fmt.Println(modeltmp[0].AuditDate) ApplyDate, _ := time.Parse("2006-01-02", modeltmp[0].ApplyDate.AddDate(0, sAddLimitMonth, 0).Format("2006-01-02")) nowtime, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02")) fmt.Println(ApplyDate, nowtime) if nowtime.Before(ApplyDate) { errinfo.Message = "增项申请时间未到!请" + ApplyDate.Format("2006-01-02") + "日以后再来申请" errinfo.Code = -1 errinfo.Info = model.Id this.Data["json"] = &errinfo this.ServeJSON() return } } style, _ := strconv.Atoi(modeltmp[0].InStyle) if style != 6 { id := strconv.Itoa(modeltmp[0].SupplierId) sqlCount := "select count(*) from OilSupplierCertAppend where SupplierId=" + id + " AND YEAR(CreateOn)=YEAR(NOW()) AND AppendType = '" + model.AppendType + "'" var countRes, _ = svc.DBE.Query(sqlCount) if len(countRes) > 0 { results := countRes[0] var count int64 for _, value := range results { count, _ = strconv.ParseInt(string(value), 10, 64) break } if count >= 2 { errinfo.Message = "除招标准入外,增项申请每年只能申请2次!" errinfo.Code = -1 errinfo.Info = model.Id this.Data["json"] = &errinfo this.ServeJSON() return } } } } svc.GetEntityByWhere(OilSupplierCertName, where, &cermodel) //if cermodel.Status != "8" { // errinfo.Message = "入库后才能提交增项!" // errinfo.Code = -1 // this.Data["json"] = &errinfo // this.ServeJSON() // return //} //添加增项信息 model.AccessCardNo = cermodel.AccessCardNo model.InStyle = cermodel.InStyle model.ApplyDate = time.Now() //申请日期 model.CreateOn = time.Now() model.CreateBy = this.User.Realname model.CreateUserId, _ = utils.StrTo(this.User.Id).Int() _, err := svc.InsertEntityBytbl(OilSupplierCertAppendName, &model) //查询准入范围 var certsublist []suppliercertsub.OilSupplierCertSub suwhere := " SupplierCertId = " + utils.ToStr(model.SupplierCertId) + " and SupplierTypeCode = " + model.AppendType svc.GetEntitysByWhere(OilSupplierCertSubName, suwhere, &certsublist) if err == nil { errinfo.Message = "操作成功!" errinfo.Code = 0 errinfo.Item = certsublist errinfo.Info = 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 *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", "InStyle", "ApplyDate", "RecUnitFlag", "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 } //定义session var session *xorm.Session session = utils.DBE.NewSession() svc := suppliercertappend.GetOilSupplierCertAppendSession(session) svcSub := suppliercertappendsub.GetOilSupplierCertAppendSubSession(session) //"session开始" 之前,首先定义 "session关闭" defer session.Close() err := session.Begin() where := "SupplierCertAppendId = " + Id //删除资质表信息 var submodel []suppliercertsub.OilSupplierCertSub svc.GetEntitysByWhere(OilSupplierCertSubName, where, &submodel) if len(submodel) > 0 { filewhere := " SupplierId = " + utils.ToStr(submodel[0].SupplierId) + " and SupType = 2 and SupplierTypeCode = '" + submodel[0].SupplierTypeCode + "'" err = svcSub.DeleteEntityBytbl(OilSupplierFileName, filewhere) if err != nil { //回滚操作 session.Rollback() } } //删除准入范围表信息 err = svcSub.DeleteEntityBytbl(OilSupplierCertSubName, where) if err != nil { //回滚操作 session.Rollback() } //最后删除主表信息 var model suppliercertappend.OilSupplierCertAppend var entityempty suppliercertappend.OilSupplierCertAppend 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 { session.Rollback() } //提交操作 err = session.Commit() if err == nil { activitiService := workflow.GetActivitiService(utils.DBE) var deleteProcessVM workflow.DeleteProcessVM if model.WorkFlowId != "" && model.WorkFlowId != "0" { deleteProcessVM.ProcessInstanceId = model.WorkFlowId deleteProcessVM.DeleteReason = "未审批通过,被申请人删除" activitiService.DeleteComplete(deleteProcessVM) } 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} []supplier.OilSupplierView // @router /mytasks [get] func (this *OilSupplierCertAppendController) GetMyTaskEntityList() { //获取分页信息 page := this.GetPageInfoForm() where := " 1=1 " orderby := "Id" asc := false Order := this.GetString("Order") where = where + " and Status>0" 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") AppendType := this.GetString("AppendType") 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 AppendType != "" { where = where + " and AppendType like '" + AppendType + "'" } 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 + "'" } } //找出待办任务 actisvc := workflow.GetActivitiService(utils.DBE) var appendIdList string str := actisvc.GetMyTasks(workflow.OIL_ENUSER_APPEND_APPLY, this.User.Id) if str != "" { appendIdList = str appendIdList = appendIdList + "," } appendIdList = strings.Trim(appendIdList, ",") appendIdarr := strings.Split(appendIdList, ",") for i, item := range appendIdarr { idx := strings.Index(item, "-") if idx >= 0 { appendIdarr[i] = strings.Split(item, "-")[0] } } appendIdList = strings.Join(appendIdarr, ",") var list []suppliercertappend.OilSupplierCertAppend var total int64 = 0 if appendIdList != "" { where += " and Id in (" + appendIdList + ")" svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) 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} controllers.Request // @router /audit/:id [post] func (this *OilSupplierCertAppendController) AuditEntity() { certappendId := this.Ctx.Input.Param(":id") firstAudit := this.GetString("FirstAuditName") SecondAudit := this.GetString("SecondAudit") ThirdAudit := this.GetString("ThirdAudit") AuditRemark := this.GetString("AuditRemark") typeCode := this.GetString("TypeCode") var setting auditsetting.Base_OilAuditSetting var userlist []userRole.Base_User usvc := userRole.GetUserService(utils.DBE) where := "" if this.User.IsCompanyUser == 1 { if typeCode == "01" { where = "AuditStepCode='" + workflow.SUB_OFFICE_WZ + "'" } else if typeCode == "02" { where = "AuditStepCode='" + workflow.SUB_OFFICE_JS + "'" } else if typeCode == "03" { where = "AuditStepCode='" + workflow.SUB_OFFICE_JF + "'" } usvc.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=" + firstAudit usvc.GetEntities(&userlist, where) } userIds := "" for _, tmpUser := range userlist { userIds += strconv.Itoa(tmpUser.Id) + "," } firstAudit = strings.Trim(userIds, ",") } //取出审批列表 certSrv := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend certSrv.GetEntityById(certappendId, &supplierCertAppendEntity) var supplierEntity supplier.OilSupplier certSrv.GetEntityById(supplierCertAppendEntity.SupplierId, &supplierEntity) var historworkflowid string historworkflowid = supplierCertAppendEntity.WorkFlowId 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 suppappend suppliercertappend.OilSupplierCertAppend //第二次提交先清空工作流 if supplierCertAppendEntity.AuditIndex > 0 { suppappend.WorkFlowId = "" cols := []string{ "WorkflowId", } certSrv.UpdateEntityByIdCols(certappendId, suppappend, cols) supplierCertAppendEntity.WorkFlowId = "" } svcActiviti := workflow.GetActivitiService(utils.DBE) processInstanceId := "" businessKey := "" result := strconv.Itoa(this.User.IsCompanyUser) if supplierCertAppendEntity.WorkFlowId == "0" || len(supplierCertAppendEntity.WorkFlowId) <= 0 { //启动工作流 businessKey = certappendId + "-" + strconv.Itoa(supplierCertAppendEntity.AuditIndex) processInstanceId = svcActiviti.StartProcess2(workflow.OIL_ENUSER_APPEND_APPLY, businessKey, this.User.Id, result, supplierCertAppendEntity.AppendType, supplierCertAppendEntity.SupplierName) } var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY ActiComplete.BusinessKey = businessKey ActiComplete.UserNames = firstAudit ActiComplete.UserId = this.User.Id ActiComplete.Result = result ActiComplete.Remarks = AuditRemark ActiComplete.CallbackUrl = "" receiveVal := svcActiviti.TaskComplete(ActiComplete) var cert suppliercert.OilSupplierCert svc := suppliercert.GetOilSupplierCertService(utils.DBE) colscert := []string{ "IsRestrict", } cert.IsRestrict = 1 svc.UpdateEntityBytbl(OilSupplierCertName, supplierCertAppendEntity.SupplierCertId, &cert, colscert) if receiveVal == "true" { if supplierCertAppendEntity.AuditIndex > 0 { // 审批历史 var audithistoryentity audithistory.Base_AuditHistory audithistoryentity.EntityId, _ = strconv.Atoi(certappendId) audithistoryentity.WorkflowId = historworkflowid audithistoryentity.Process = workflow.OIL_ENUSER_APPEND_APPLY audithistoryentity.BusinessKey = businessKey audithistoryentity.Type = supplierCertAppendEntity.AppendType audithistoryentity.BackStep = supplierCertAppendEntity.Status audithistoryentity.Index = supplierCertAppendEntity.AuditIndex audithistoryentity.CreateOn = time.Now() audithistoryentity.CreateBy = this.User.Realname audithistoryentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int() certSrv.InsertEntity(audithistoryentity) } 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(首次提交时才会记录,中间状态请忽略) 及审批状态 var model suppliercertappend.OilSupplierCertAppend model.WorkFlowId = processInstanceId if this.User.IsCompanyUser == 1 { model.Status = suppliercert.FEN_TRIAL_STATUS //分办 } else if this.User.IsCompanyUser == 0 { model.Status = suppliercert.FIRST_TRIAL_STATUS //二级单位初审 } model.FirstAudit, _ = strconv.Atoi(firstAudit) model.SecondAudit, _ = strconv.Atoi(SecondAudit) model.ThirdAudit, _ = strconv.Atoi(ThirdAudit) model.AuditIndex = supplierCertAppendEntity.AuditIndex model.BusinessKey = businessKey model.ProcessKey = ActiComplete.ProcessKey cols := []string{ "Id", "WorkFlowId", "Status", "FirstAudit", "SecondAudit", "ThirdAudit", "AuditIndex", "BusinessKey", "ProcessKey", } certSrv.UpdateEntityByIdCols(certappendId, model, cols) } // @Title 企业用户提交审批----启动工作流 // @Description 企业用户提交按钮 // @Success 200 {object} controllers.Request // @router /company-audit/:id [post] func (this *OilSupplierCertAppendController) CompanySubmitAuditEntity() { certAppendId := this.Ctx.Input.Param(":id") unitId := this.GetString("UnitId") AuditRemark := this.GetString("AuditRemark") 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() } }() if this.User.IsCompanyUser == 0 { // 0二级单位; 1企业用户 panic("非企业用户,请用分办功能提交!") } //取出准入申请表 certSrv := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend certSrv.GetEntityById(certAppendId, &supplierCertAppendEntity) // 检查是否允许提交 certSrv.IsSupplierCertAppendCanSubmit(strconv.Itoa(supplierCertAppendEntity.SupplierId), certAppendId) stepCode := workflow.GetWorkFlowStepCode(supplierCertAppendEntity.AppendType) auditSettingService := auditsetting.GetOilAuditSettingService(utils.DBE) approverIds := auditSettingService.GetApproverIdsByStepCodeAndUnitId(stepCode, unitId) if approverIds == "" { panic("该分办单位未配置审批人") } //取出企业主表 supplierSvc := supplier.GetOilSupplierService(utils.DBE) var supplierEntity supplier.OilSupplier //检查是否可提交 supplierSvc.GetEntityById(supplierCertAppendEntity.SupplierId, &supplierEntity) status, _ := strconv.Atoi(supplierCertAppendEntity.Status) if status > 0 { panic("工作流已经启动,请刷新重试!") } svcActiviti := workflow.GetActivitiService(utils.DBE) //启动工作流 businessKey := supplierCertAppendEntity.BusinessKey processInstanceId := supplierCertAppendEntity.WorkFlowId // 如果被驳回,不再新启工作流 if processInstanceId == "" { businessKey = certAppendId + "-" + strconv.Itoa(supplierCertAppendEntity.AuditIndex) processInstanceId = svcActiviti.StartProcess2(workflow.OIL_ENUSER_APPEND_APPLY, businessKey, this.User.Id, "1", supplierCertAppendEntity.AppendType, supplierEntity.SupplierName) if len(processInstanceId) <= 0 { panic("工作流启动失败!") } supplierCertAppendEntity.AuditIndex += 1 } // 将启动和工作流,选择的初审和复审人员保存下来 cols := []string{ "Id", "WorkflowId", "BusinessKey", "ProcessKey", "CommitComId", "AuditIndex", } supplierCertAppendEntity.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY supplierCertAppendEntity.BusinessKey = businessKey supplierCertAppendEntity.WorkFlowId = processInstanceId supplierCertAppendEntity.CommitComId = unitId certSrv.UpdateEntityByIdCols(certAppendId, supplierCertAppendEntity, cols) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY ActiComplete.BusinessKey = businessKey ActiComplete.UserId = this.User.Id ActiComplete.Result = "1" //提交给二级单位分办 ActiComplete.Remarks = AuditRemark ActiComplete.CallbackUrl = utils.Cfg.MustValue("workflow", "callbackHost") receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { log.Println("工作流异常, 业务ID:"+supplierCertAppendEntity.BusinessKey+", 流程ID:"+supplierCertAppendEntity.WorkFlowId, " 工作流传参: ", ActiComplete, receiveVal) panic("任务已审批,请刷新!") } // 记录申请快照 选择在准入项更新以后记录快照,防止第一次审批未通过后又改变了准入范围(待验证)。 // CertSubStatus字段 -1是什么状态 supplierLogService := supplierlog.GetSupplierLogService(utils.DBE) sourceId, _ := strconv.Atoi(certAppendId) supplierLogService.SaveSupplierLogForAppend(supplierCertAppendEntity.SupplierId, sourceId) // 增项 } // @Title 二级分办单位提交审批----启动工作流 // @Description 二级分办单位提交审批按钮 // @Success 200 {object} controllers.Request // @router /unit-audit/:id [post] func (this *OilSupplierCertAppendController) SeparateUnitSubmitAuditEntity() { certAppendId := this.Ctx.Input.Param(":id") firstAudit := this.GetString("firstAudit") secondAudit := this.GetString("SecondAudit") thirdAudit := this.GetString("ThirdAudit") auditRemark := this.GetString("AuditRemark") userId := this.User.Id var baseUserInfo userRole.Base_User userService := userRole.GetUserService(utils.DBE) userService.GetEntityById(userId, &baseUserInfo) unitId := baseUserInfo.UnitId 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() } }() if firstAudit == "" || secondAudit == "" { panic("请选择审批人") } certSrv := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend certSrv.GetEntityById(certAppendId, &supplierCertAppendEntity) var supplierEntity supplier.OilSupplier certSrv.GetEntityById(supplierCertAppendEntity.SupplierId, &supplierEntity) svcActiviti := workflow.GetActivitiService(utils.DBE) //启动工作流 businessKey := supplierCertAppendEntity.BusinessKey processInstanceId := supplierCertAppendEntity.WorkFlowId // 如果被驳回,不再新启工作流 if processInstanceId == "" { businessKey = certAppendId + "-" + strconv.Itoa(supplierCertAppendEntity.AuditIndex) processInstanceId = svcActiviti.StartProcess2(workflow.OIL_ENUSER_APPEND_APPLY, businessKey, this.User.Id, "1", supplierCertAppendEntity.AppendType, supplierEntity.SupplierName) if len(processInstanceId) <= 0 { panic("工作流启动失败!") } supplierCertAppendEntity.AuditIndex += 1 } // 将启动和工作流,选择的初审和复审人员保存下来 cols := []string{ "Id", "FirstAudit", "SecondAudit", "thirdAudit", "WorkFlowId", "BusinessKey", "ProcessKey", "CommitComId", "AuditIndex", } supplierCertAppendEntity.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY supplierCertAppendEntity.BusinessKey = businessKey supplierCertAppendEntity.WorkFlowId = processInstanceId supplierCertAppendEntity.FirstAudit, _ = strconv.Atoi(firstAudit) supplierCertAppendEntity.SecondAudit, _ = strconv.Atoi(secondAudit) supplierCertAppendEntity.ThirdAudit, _ = strconv.Atoi(thirdAudit) supplierCertAppendEntity.CommitComId = strconv.Itoa(unitId) certSrv.UpdateEntityByIdCols(certAppendId, supplierCertAppendEntity, cols) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY ActiComplete.BusinessKey = supplierCertAppendEntity.BusinessKey ActiComplete.UserId = this.User.Id // 当前审批操作人员 //ActiComplete.UserNames = secondAudit // 当前审批操作人员 ActiComplete.Result = "2" //分办提交给二级单位初审 ActiComplete.Remarks = auditRemark ActiComplete.CallbackUrl = utils.Cfg.MustValue("workflow", "callbackHost") receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { log.Println("工作流异常, 业务ID:"+supplierCertAppendEntity.BusinessKey+", 流程ID:"+supplierCertAppendEntity.WorkFlowId, " 工作流传参: ", ActiComplete, receiveVal) panic("任务已审批,请刷新!") } // 记录申请快照 选择在准入项更新以后记录快照,防止第一次审批未通过后又改变了准入范围(待验证)。 // CertSubStatus字段 -1是什么状态 supplierLogService := supplierlog.GetSupplierLogService(utils.DBE) sourceId, _ := strconv.Atoi(certAppendId) supplierLogService.SaveSupplierLogForAppend(supplierCertAppendEntity.SupplierId, sourceId) // 增项 } // @Title 二级单位分办 --审批 // @Description 二级分办 // @Success 200 {object} controllers.Request // @router /separate-audit/:id [post] func (this *OilSupplierCertAppendController) AppendSeparateAuditEntity() { certAppendId := this.Ctx.Input.Param(":id") Result := this.GetString("Result") firstAudit := this.GetString("FirstAudit") secondAudit := this.GetString("SecondAudit") thirdAudit := this.GetString("ThirdAudit") // typeCode := this.GetString("TypeCode") AuditRemark := this.GetString("AuditRemark") 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() } }() // 取出准入表信息 certSrv := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend certSrv.GetEntityById(certAppendId, &supplierCertAppendEntity) if Result == "1" { if firstAudit == "" || secondAudit == "" { panic("请选择审批人") } // 将选择的初审和复审人员保存下来 cols := []string{ "FirstAudit", "SecondAudit", "thirdAudit", } supplierCertAppendEntity.FirstAudit, _ = strconv.Atoi(firstAudit) supplierCertAppendEntity.SecondAudit, _ = strconv.Atoi(secondAudit) supplierCertAppendEntity.ThirdAudit, _ = strconv.Atoi(thirdAudit) // 专业处室 certSrv.UpdateEntityByIdCols(certAppendId, supplierCertAppendEntity, cols) } svcActiviti := workflow.GetActivitiService(utils.DBE) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY ActiComplete.BusinessKey = supplierCertAppendEntity.BusinessKey ActiComplete.UserId = this.User.Id // 审批人员 // ActiComplete.UserNames = secondAudit // 初审人员 ActiComplete.Result = Result //分办完成后只向前走 ActiComplete.Remarks = AuditRemark ActiComplete.CallbackUrl = utils.Cfg.MustValue("workflow", "callbackHost") receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { log.Println("工作流异常, 业务ID:"+supplierCertAppendEntity.BusinessKey+", 流程ID:"+supplierCertAppendEntity.WorkFlowId, " 工作流传参: ", ActiComplete, receiveVal) panic("任务已审批,请刷新!") } } // @Title 分办之后的各级审批 --审批 包含:二级单位初审、复审, 业务处室专业审核 // @Description 分办之后的各级审批 // @Success 200 {object} controllers.Request // @router /common-audit/:id [post] func (this *OilSupplierCertAppendController) AppendCommonAuditEntity() { certAppendId := this.Ctx.Input.Param(":id") result := this.GetString("result") AuditRemark := this.GetString("AuditRemark") 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() } }() //取出准入表信息 certSrv := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend certSrv.GetEntityById(certAppendId, &supplierCertAppendEntity) svcActiviti := workflow.GetActivitiService(utils.DBE) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY ActiComplete.BusinessKey = supplierCertAppendEntity.BusinessKey ActiComplete.UserId = this.User.Id //审批人员 ActiComplete.Result = result //前台审批[同意、不同意] ActiComplete.Remarks = AuditRemark ActiComplete.CallbackUrl = utils.Cfg.MustValue("workflow", "callbackHost") receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { log.Println("工作流异常, 业务ID:"+supplierCertAppendEntity.BusinessKey+", 流程ID:"+supplierCertAppendEntity.WorkFlowId, " 工作流传参: ", ActiComplete, receiveVal) panic("任务已审批,请刷新!") } } // @Title 业务处室接收分办 专业审批 // @Description 业务处室接收分办 专业审批 // @Success 200 {object} controllers.Request // @router /business-separate-audit/:id [post] func (this *OilSupplierCertAppendController) AppendBusinessOfficeSeparateAuditEntity() { certAppendId := this.Ctx.Input.Param(":id") Result := this.GetString("Result") ProfessionalAudit := this.GetString("ProfessionalAudit") AuditRemark := this.GetString("AuditRemark") 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() } }() //取出准入表信息 certSrv := suppliercert.GetOilSupplierCertService(utils.DBE) var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend certSrv.GetEntityById(certAppendId, &supplierCertAppendEntity) // 保证工作流上信息显示准确,暂不考虑异常 if Result == "1" { cols := []string{ "Id", "Status", "ProfessionalAudit", } supplierCertAppendId := strings.Split(supplierCertAppendEntity.BusinessKey, "-")[0] supplierCertAppendEntity.Status = suppliercert.PROF_AUDIT_STATUS //专业处室接收 supplierCertAppendEntity.ProfessionalAudit, _ = strconv.Atoi(ProfessionalAudit) certSrv.UpdateEntityByIdCols(supplierCertAppendId, supplierCertAppendEntity, cols) } svcActiviti := workflow.GetActivitiService(utils.DBE) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY ActiComplete.BusinessKey = supplierCertAppendEntity.BusinessKey ActiComplete.UserId = this.User.Id //审批人员 ActiComplete.Result = Result //前台审批[同意、不同意] ActiComplete.UserNames = ProfessionalAudit // 直接分配业务处室专业审批人 ActiComplete.Remarks = AuditRemark ActiComplete.CallbackUrl = utils.Cfg.MustValue("workflow", "callbackHost") receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { log.Println("工作流异常, 业务ID:"+supplierCertAppendEntity.BusinessKey+", 流程ID:"+supplierCertAppendEntity.WorkFlowId, " 工作流传参: ", ActiComplete, receiveVal) panic("任务已审批,请刷新!") } } // @Title 集中审批 // @Description 集中审批 // @Success 200 {object} controllers.Request // @router /concentrate-audit/:id [post] func (this *OilSupplierCertAppendController) AppendConcentrateAuditEntity() { certAppendId := this.Ctx.Input.Param(":id") AuditRemark := this.GetString("AuditRemark") // TODO 前台选择的审批结果 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() } }() //取出准入表信息 certSrv := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend certSrv.GetEntityById(certAppendId, &supplierCertAppendEntity) svcActiviti := workflow.GetActivitiService(utils.DBE) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY ActiComplete.BusinessKey = supplierCertAppendEntity.BusinessKey ActiComplete.UserId = this.User.Id //审批人员 ActiComplete.Result = "1" //前台审批[同意、不同意] // TODO 前台选择的审批结果 ActiComplete.Remarks = AuditRemark ActiComplete.CallbackUrl = utils.Cfg.MustValue("workflow", "callbackHost") receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { log.Println("工作流异常, 业务ID:"+supplierCertAppendEntity.BusinessKey+", 流程ID:"+supplierCertAppendEntity.WorkFlowId, " 工作流传参: ", ActiComplete, receiveVal) panic("任务已审批,请刷新!") } //cols := []string{ // "Id", // "Status", //} //supplierCertId := strings.Split(supplierCertEntity.BusinessKey, "-")[0] //supplierCertEntity.Status = suppliercert.PROF_AUDIT_STATUS //专业处室接收 //certSrv.UpdateEntityByIdCols(supplierCertId, supplierCertEntity, cols) } // @Title 确认是否入库 // @Description 确认是否入库 // @Success 200 {object} controllers.Request // @router /update-is-storage/:id [post] func (this *OilSupplierCertAppendController) UpdateIsStorage() { id := this.Ctx.Input.Param(":id") status := this.GetString("Status") //PACNumber := this.GetString("PACNumber") //SupplierId := this.GetString("SupplierId") var errinfo ErrorInfo if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } defer func() { //finally处理失败的异常 if err := recover(); err != nil { errinfo.Message = err.(string) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } else { //返回正确结果 if status == "1" { errinfo.Message = "入库成功" } else { errinfo.Message = "退回成功" } errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } }() var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend certAppendSrv := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) certAppendSrv.GetEntityById(id, &supplierCertAppendEntity) //var supplierEntity supplier.OilSupplier //srv := supplier.GetOilSupplierService(utils.DBE) //srv.GetEntityById(SupplierId, &supplierEntity) //supplierEntity.PACNumber = PACNumber //srvCols := []string{"PACNumber"} //srv.UpdateEntityByIdCols(SupplierId, &supplierEntity, srvCols) AuditRemark := "" fmt.Println("审批入库传入状态:", status) if status == "1" { AuditRemark = "审批通过已入库。" } else { status = "0" AuditRemark = "入库退回。" } svcActiviti := workflow.GetActivitiService(utils.DBE) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY ActiComplete.BusinessKey = supplierCertAppendEntity.BusinessKey ActiComplete.UserId = this.User.Id //审批人员 ActiComplete.Result = status //前台审批[同意、不同意] ActiComplete.Remarks = AuditRemark ActiComplete.CallbackUrl = utils.Cfg.MustValue("workflow", "callbackHost") receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { log.Println("工作流异常, 业务ID:"+supplierCertAppendEntity.BusinessKey+", 流程ID:"+supplierCertAppendEntity.WorkFlowId, " 工作流传参: ", ActiComplete, receiveVal) panic("任务已审批,请刷新!") } } // @Title 审批 // @Description 审批 // @Param body body suppliercert.OilSupplierCert // @Success 200 {object} controllers.Request // @router /auditEntityFir/:id [post] func (this *OilSupplierCertAppendController) AuditEntityFir() { appendId := this.Ctx.Input.Param(":id") firstAudit := this.GetString("FirstAuditName") secondAudit := this.GetString("SecondAudit") thirdAudit := this.GetString("ThirdAudit") //取出审批列表 //certSrv := suppliercert.GetOilSupplierCertService(utils.DBE) svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend svc.GetEntityById(appendId, &supplierCertAppendEntity) var supplierEntity supplier.OilSupplier wheresup := "Id=" + strconv.Itoa(supplierCertAppendEntity.SupplierId) svc.GetEntity(&supplierEntity, wheresup) var jsonblob = this.Ctx.Input.RequestBody var dataother AppShenHeModel json.Unmarshal(jsonblob, &dataother) 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 supplierCertAppendEntity.Status == suppliercert.FEN_TRIAL_STATUS { userIds = firstAudit status = suppliercert.FIRST_TRIAL_STATUS backstatus = suppliercert.NO_FEN_TRIAL_STATUS step = 2 if dataother.SuccessStatus == 1 { supplierCertAppendEntity.FirstAudit, _ = strconv.Atoi(firstAudit) supplierCertAppendEntity.SecondAudit, _ = strconv.Atoi(secondAudit) supplierCertAppendEntity.ThirdAudit, _ = strconv.Atoi(thirdAudit) cols := []string{ "Id", "FirstAudit", "SecondAudit", "ThirdAudit", } svc.UpdateEntityByIdCols(appendId, supplierCertAppendEntity, cols) } } if supplierCertAppendEntity.Status == suppliercert.FIRST_TRIAL_STATUS { userIds = utils.ToStr(supplierCertAppendEntity.SecondAudit) status = suppliercert.SECOND_TRIAL_STATUS step = 2 backstatus = suppliercert.NOPASS_STATUS } else if supplierCertAppendEntity.Status == suppliercert.SECOND_TRIAL_STATUS { svc := organize.GetOrganizeService(utils.DBE) unitId := svc.GetMyUnitDepartmentId(strconv.Itoa(supplierCertAppendEntity.ThirdAudit)) step = 2 backstatus = suppliercert.NO_SECOND_TRIAL_STATUS var userlist []userRole.Base_User var setting auditsetting.Base_OilAuditSetting usvc := userRole.GetUserService(utils.DBE) if supplierCertAppendEntity.InStyle == "3" && supplierEntity.MgrUnit == supplier.MGRUNIT { status = suppliercert.CENT_AUDIT_STATUS where := "AuditStepCode='" + workflow.PROF_REGULATION + "'" usvc.GetEntity(&setting, where) paramSvc := baseparameter.GetBaseparameterService(utils.DBE) topid := paramSvc.GetBaseparameterMessage("", "paramset", "CENT_AUDIT") 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 usvc.GetEntities(&userlist, where) } } else if supplierCertAppendEntity.InStyle == "3" && supplierEntity.MgrUnit != supplier.MGRUNIT { status = suppliercert.CENT_AUDIT_STATUS step = 2 backstatus = suppliercert.NO_PROF_AUDIT_STATUS 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 + "'" usvc.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 usvc.GetEntities(&userlist, where) } for _, tmpUser := range userlist { userIds += strconv.Itoa(tmpUser.Id) + "," } userIds = strings.Trim(userIds, ",") } else if supplierCertAppendEntity.InStyle == "2" || supplierCertAppendEntity.InStyle == "4" || supplierCertAppendEntity.InStyle == "6" { step = 2 status = suppliercert.ALL_PASE_STATUS backstatus = suppliercert.NO_SECOND_TRIAL_STATUS } else { status = suppliercert.THIRD_TRIAL_STATUS where := "AuditStepCode='" + workflow.PROF_RECE + "'" 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=" + unitId svc.GetEntities(&userlist, where) } } for _, tmpUser := range userlist { userIds += strconv.Itoa(tmpUser.Id) + "," //strconv.FormatInt(tmpUser.Id, 10) + "," } userIds = strings.Trim(userIds, ",") } else if supplierCertAppendEntity.Status == suppliercert.THIRD_TRIAL_STATUS { userIds = utils.ToStr(dataother.Auditer) status = suppliercert.PROF_AUDIT_STATUS step = 2 backstatus = suppliercert.NO_THIRD_TRIAL_STATUS } else if supplierCertAppendEntity.Status == suppliercert.PROF_AUDIT_STATUS { if supplierCertAppendEntity.InStyle == "3" { status = suppliercert.PAYING_AUDIT_STATUS step = 3 backstatus = suppliercert.NO_CENT_AUDIT_STATUS } else { status = suppliercert.CENT_AUDIT_STATUS step = 2 backstatus = suppliercert.NO_PROF_AUDIT_STATUS 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 + "'" usvc.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 usvc.GetEntities(&userlist, where) } for _, tmpUser := range userlist { userIds += strconv.Itoa(tmpUser.Id) + "," } userIds = strings.Trim(userIds, ",") } } else if supplierCertAppendEntity.Status == suppliercert.CENT_AUDIT_STATUS { userIds = utils.ToStr(dataother.Auditer) status = suppliercert.PAYING_AUDIT_STATUS step = 3 backstatus = suppliercert.NO_CENT_AUDIT_STATUS } svcActiviti := workflow.GetActivitiService(utils.DBE) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = supplierCertAppendEntity.ProcessKey ActiComplete.BusinessKey = supplierCertAppendEntity.BusinessKey ActiComplete.UserNames = userIds ActiComplete.UserId = this.User.Id ActiComplete.Remarks = dataother.AuditorRemark ActiComplete.CallbackUrl = "" if dataother.SuccessStatus == 1 { ActiComplete.Result = "1" receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal == "true" { if supplierCertAppendEntity.Status == "5" { if supplierCertAppendEntity.InStyle == suppliercert.PINGSHEN { // 评审准入 wheresup := " SupplierCertAppendId=" + strconv.Itoa(supplierCertAppendEntity.Id) + " and Type='2'" var sup []suppliercertsub.OilSupplierCertSub total := svc.GetPagingEntitiesWithOrder(1, 10, "Id", true, &sup, wheresup) dictSvc := items.GetItemsService(utils.DBE) appendAmt := dictSvc.GetKeyValueItems("SupplierAppend") appendi, _ := strconv.Atoi(appendAmt[0].Value) if supplierCertAppendEntity.AppendType == suppliercert.DOOGS_TYPECODE && total <= int64(appendi) { // 物资类 小于等于50条不交费 status = suppliercert.ALL_PASE_STATUS } else { paysvc := paymentinfo.GetPaymentService(utils.DBE) var Amount float64 asvc := oilcostmanage.GetOilCostManageService(utils.DBE) Amount = asvc.GetAmount("APPEND", supplierCertAppendEntity.AppendType) var payinfo paymentinfo.OilPaymentInfo payinfo.SrcId = supplierCertAppendEntity.Id payinfo.SupplierId = supplierCertAppendEntity.SupplierId payinfo.SupplierCertId = supplierCertAppendEntity.SupplierCertId payinfo.USCCode = supplierEntity.CommercialNo payinfo.SupplierName = supplierEntity.SupplierName payinfo.PayType = "3" payinfo.IsPay = "0" payinfo.IsInvoice = "0" payinfo.Amount = strconv.FormatFloat(Amount, 'E', -1, 64) payinfo.CreateUserId = supplierCertAppendEntity.CreateUserId payinfo.CreateBy = supplierCertAppendEntity.CreateBy payinfo.CreateOn = time.Now() paysvc.InsertEntity(&payinfo) //发短信 toMobile := supplierEntity.Mobile bFlag := "" if supplierCertAppendEntity.AppendType == "01" { bFlag = "物资类" } else if supplierCertAppendEntity.AppendType == "02" { bFlag = "基建类" } else { bFlag = "服务类" } msg := "您的" + bFlag + "增项审核通过,请及时确认信息并交费!" msgService := msg2.GetMsgService(utils.DBE) msgService.HandleMsg(toMobile, msg, "4-1", supplierCertAppendEntity.CreateBy, supplierEntity.ContactName, strconv.Itoa(supplierCertAppendEntity.CreateUserId), this.User.Username) } //var model suppliercertsub.OilSupplierCertSub //model.Type = "3" //model.ModifiedOn = time.Now() //model.ModifiedBy = this.User.Realname //model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() //colssup := []string{ // "Type", // "ModifiedOn", // "ModifiedUserId", // "ModifiedBy", //} //svc.UpdateEntityBywheretbl(OilSupplierCertSubName, &model, colssup, wheresup) //paysvc.AddPaymentinfo(supplierCertAppendEntity.SupplierId, supplierCertAppendEntity.Id, Amount, "3") } else { status = suppliercert.ALL_PASE_STATUS } // 信息变更 var infoitems []suppliercertappendsub.OilAppendChangeItem where := "SupplierId = " + utils.ToStr(supplierCertAppendEntity.SupplierId) + " and InfoId = " + utils.ToStr(supplierCertAppendEntity.Id) svc.GetEntities(&infoitems, where) this.updatesupplier(OilSupplierName, supplierCertAppendEntity.SupplierId, infoitems) // 更新资质 var qualdetail []suppliercertappendsub.OilAppendChangeDetail wheres := "SupplierId = " + utils.ToStr(supplierCertAppendEntity.SupplierId) + " and ParentId=" + strconv.Itoa(supplierCertAppendEntity.Id) svc.GetEntities(&qualdetail, wheres) 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 svc.UpdateEntityBytbl(OilSupplierFileName, qualdetail[i].FileId, &supfilemodel, []string{"FileName", "FileUrl", "EffectDate"}) } } } if status == suppliercert.ALL_PASE_STATUS { appsvc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) //更新准入项表 appendwhere := " SupplierId = " + utils.ToStr(supplierCertAppendEntity.SupplierId) + " and SupplierCertId = " + utils.ToStr(supplierCertAppendEntity.SupplierCertId) + " and Type = '2'" var appendsubmodel suppliercertsub.OilSupplierCertSub appendsubmodel.Type = "3" appsvc.UpdateEntityBywheretbl(OilSupplierCertSubName, &appendsubmodel, []string{"Type"}, appendwhere) //更新资质表 appendfilewhere := " SupplierId = " + utils.ToStr(supplierCertAppendEntity.SupplierId) + " and SupType = 2" var appendsubfilemodel supplierfile.OilSupplierFile appendsubfilemodel.SupType = 3 appsvc.UpdateEntityBywheretbl(OilSupplierCertSubName, &appendsubfilemodel, []string{"SupType"}, appendfilewhere) //更新增项表 appdwhere := " SupplierId = " + utils.ToStr(supplierCertAppendEntity.SupplierId) + " and SupplierCertId = " + utils.ToStr(supplierCertAppendEntity.SupplierCertId) + " and Status = '6'" var appendmodel suppliercertappend.OilSupplierCertAppend appendmodel.Status = suppliercert.ALL_PASE_STATUS appsvc.UpdateEntityBywheretbl(OilSupplierCertAppendName, &appendmodel, []string{"Status"}, appdwhere) // 信息变更 var infoitems []suppliercertappendsub.OilAppendChangeItem where := "SupplierId = " + utils.ToStr(supplierCertAppendEntity.SupplierId) + " and InfoId = " + utils.ToStr(supplierCertAppendEntity.Id) svc.GetEntities(&infoitems, where) this.updatesupplier(OilSupplierName, supplierCertAppendEntity.SupplierId, infoitems) // 更新资质 var qualdetail []suppliercertappendsub.OilAppendChangeDetail wheres := "SupplierId = " + utils.ToStr(supplierCertAppendEntity.SupplierId) + " and ParentId=" + strconv.Itoa(supplierCertAppendEntity.Id) svc.GetEntities(&qualdetail, wheres) 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 svc.UpdateEntityBytbl(OilSupplierFileName, qualdetail[i].FileId, &supfilemodel, []string{"FileName", "FileUrl", "EffectDate"}) } } } supplierCertAppendEntity.Status = status supplierCertAppendEntity.Step = step supplierCertAppendEntity.AuditDate = time.Now() cols := []string{ "Status", "Step", "AuditDate", } svc.UpdateEntityByIdCols(appendId, supplierCertAppendEntity, cols) errinfo.Message = "提交成功!" errinfo.Code = 0 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 supplierCertAppendEntity.Status == "5" { supplierCertAppendEntity.Status = backstatus supplierCertAppendEntity.Step = step supplierCertAppendEntity.AuditIndex = supplierCertAppendEntity.AuditIndex + 1 } else { supplierCertAppendEntity.Status = backstatus supplierCertAppendEntity.Step = 1 supplierCertAppendEntity.AuditIndex = supplierCertAppendEntity.AuditIndex + 1 } cols := []string{ "Status", "Step", "AuditIndex", } _, err := svc.UpdateEntityByIdCols(appendId, supplierCertAppendEntity, cols) toMobile := supplierEntity.Mobile bFlag := "" if supplierCertAppendEntity.AppendType == "01" { bFlag = "物资类" } else if supplierCertAppendEntity.AppendType == "02" { bFlag = "基建类" } else { bFlag = "服务类" } msg := "您的" + bFlag + "增项审核未通过,请及时查看!" msgService := msg2.GetMsgService(utils.DBE) msgService.HandleMsg(toMobile, msg, "5-1", supplierCertAppendEntity.CreateBy, supplierEntity.ContactName, strconv.Itoa(supplierCertAppendEntity.CreateUserId), this.User.Username) if err == 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 *OilSupplierCertAppendController) updatesupplier(supname string, suppid int, infoitems []suppliercertappendsub.OilAppendChangeItem) error { svc := suppliercertappend.GetOilSupplierCertAppendService(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 if infoitems[i].SelectItem == "SetupTime" { sql = `UPDATE ` + supname + ` set ` + infoitems[i].SelectItem + ` = '` + infoitems[i].ChangeInfo[0:10] + `' where ` + where } else { 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 } // @Title 添加资金 // @Description 添加资金 // @Success 200 {object} // @router /addqualchange/:id [post] func (this *OilSupplierCertAppendController) AddAppChange() { 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 qualchange.OilQualChangeDetail var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) svc := qualchange.GetQualChangeService(utils.DBE) var supplierfile supplierfile.OilSupplierFile where := "SupplierId = '" + strconv.Itoa(model.SupplierId) + "' and NeedFileType='" + model.NeedFileType + "'" has := svc.GetEntity(&supplierfile, where) var tableHeader tableheader.BaseTableheader where1 := "Name = '" + model.NeedFileType + "'" svc.GetEntityByWhere(BaseTableHeader, where1, &tableHeader) if has { errinfo.Message = "操作失败!不能重复添加" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } supplierfile.SupplierId = model.SupplierId supplierfile.SupplierTypeCode = model.SupplierTypeCode supplierfile.IsManuf = tableHeader.IsManuf supplierfile.NeedFileType = model.NeedFileType supplierfile.FileType = 0 supplierfile.SupType = 2 supplierfile.CreateOn = time.Now() supplierfile.CreateUserId, _ = strconv.Atoi(this.User.Id) supplierfile.CreateBy = this.User.Realname svc.InsertEntity(&supplierfile) model.ParentId, _ = strconv.Atoi(id) model.FileId = supplierfile.Id model.FileUrl = strings.Trim(model.FileUrl, "$") model.FileName = strings.Trim(model.FileName, "$") var err error var qualdetaimodel []qualchange.OilQualChangeDetail qdwhere := " SupplierId = " + utils.ToStr(model.SupplierId) + " and FileId = " + utils.ToStr(supplierfile.Id) + " and ParentId=" + id svc.GetEntitysByWhere(OilAppendChangeDetailName, qdwhere, &qualdetaimodel) if len(qualdetaimodel) == 0 { model.CreateOn = time.Now() model.CreateBy = this.User.Realname model.CreateUserId, _ = utils.StrTo(this.User.Id).Int() _, err = svc.InsertEntityBytbl(OilAppendChangeDetailName, &model) } else { err = svc.UpdateEntityBywheretbl(OilAppendChangeDetailName, &model, []string{"OldEffectDate", "FileUrl", "FileName", "OtherRemark"}, qdwhere) } 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 /deletenewfile/:Id [delete] func (this *OilSupplierCertAppendController) DeleteNewFile() { Id := this.Ctx.Input.Param(":Id") var errinfo ErrorInfo if Id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } svc := infochange.GetInfoChangeService(utils.DBE) where := "FileId=" + Id err := svc.DeleteEntityBytbl(OilAppendChangeDetailName, where) where1 := "Id=" + Id err = svc.DeleteEntityBytbl(OilSupplierFileName, where1) 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 /update-pay-status/:id [post] func (this *OilSupplierCertAppendController) UpdatePayStatus() { certId := this.Ctx.Input.Param(":id") var errinfo ErrorInfo if certId == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } supplierCerAppendtSrv := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend supplierCerAppendtSrv.GetEntityById(certId, &supplierCertAppendEntity) paySrv := paymentinfo.GetPaymentService(utils.DBE) var paymentInfoEntities []paymentinfo.OilPaymentInfo err := paySrv.GetPaymentInfoBySrcId(certId, "3", &paymentInfoEntities) if err != nil { errinfo.Message = "未知错误,请稍后再试!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } if len(paymentInfoEntities) == 1 { for _, item := range paymentInfoEntities { if item.IsPay == "1" { errinfo.Message = "已确认交费!请耐心等待" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } if item.IsPay == "2" { errinfo.Message = "已交费!请勿重复操作!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } } sql := "UPDATE OilPaymentInfo SET IsPay ='1' where SrcId=" + certId supplierCerAppendtSrv.DBE.Exec(sql) errinfo.Message = "确认交费成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() }