| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867 |
- package oilsupplier
- import (
- "dashoo.cn/backend/api/business/audithistory"
- "dashoo.cn/backend/api/business/auditsetting"
- "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
- "dashoo.cn/backend/api/business/organize"
- "dashoo.cn/backend/api/business/register"
- "dashoo.cn/business2/parameter"
- "dashoo.cn/business2/userRole"
- "encoding/json"
- "fmt"
- "strconv"
- "strings"
- "time"
- "dashoo.cn/backend/api/business/oilsupplier/suppliercert"
- "dashoo.cn/backend/api/business/paymentinfo"
- "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 := " 1=1 "
- orderby := "Id"
- asc := false
- Order := this.GetString("Order")
- Prop := this.GetString("Prop")
- if Order != "" && Prop != "" {
- orderby = Prop
- if Order == "asc" {
- asc = true
- }
- }
- ApplyDate := this.GetString("ApplyDate")
- RecUnitId := this.GetString("RecUnitId")
- RecUnitName := this.GetString("RecUnitName")
- 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 + "'"
- }
- }
- //企业用户必须加创建人条件
- if this.User.IsCompanyUser == 1 {
- where = where + " and 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 CreateUserId = '" + this.User.Id + "'"
- }
- }
- svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
- var list []suppliercertappend.OilSupplierCertAppend
- total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
- var datainfo DataInfo
- datainfo.Items = list
- datainfo.CurrentItemCount = total
- datainfo.PageIndex = page.CurrentPage
- datainfo.ItemsPerPage = page.Size
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 通过Id获取信息
- // @Description get user by token
- // @Success 200 {object} []suppliercertappend.OilSupplierCertAppend
- // @router /getEntityById/:id [get]
- func (this *OilSupplierCertAppendController) GetEntityById() {
- Id := this.Ctx.Input.Param(":id")
- var model suppliercertappend.OilSupplierCertAppend
- svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
- svc.GetEntityByIdBytbl(OilSupplierCertAppendName, Id, &model)
- this.Data["json"] = &model
- this.ServeJSON()
- }
- // @Title 获取公司信息
- // @Description 根据创建用户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 < 6"
- has := svc.GetEntityByWhere(OilSupplierCertAppendName, where_app, &model)
- if has {
- errinfo.Message = "已提交增项申请,审批通过后才可再提交申请!"
- errinfo.Code = -1
- errinfo.Info = model.Id
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- svc.GetEntityByWhere(OilSupplierCertName, where, &cermodel)
- //if cermodel.Status != "8" {
- // errinfo.Message = "入库后才能提交增项!"
- // errinfo.Code = -1
- // this.Data["json"] = &errinfo
- // this.ServeJSON()
- // return
- //}
- //添加增项信息
- 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",
- "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 {
- 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
- if actisvc.GetMyTasks(workflow.OIL_APPEND_APPLY, this.User.Id) != "" {
- appendIdList = actisvc.GetMyTasks(workflow.OIL_APPEND_APPLY, this.User.Id)
- appendIdList = appendIdList + ","
- }
- if actisvc.GetMyTasks(workflow.OIL_FIRST_APPEND_APPLY, this.User.Id) != "" {
- appendIdList = fmt.Sprintf("%s %s", appendIdList, actisvc.GetMyTasks(workflow.OIL_FIRST_APPEND_APPLY, this.User.Id))
- appendIdList = appendIdList + ","
- }
- if actisvc.GetMyTasks(workflow.OIL_SECOND_APPEND_APPLY, this.User.Id) != "" {
- appendIdList = fmt.Sprintf("%s %s", appendIdList, actisvc.GetMyTasks(workflow.OIL_SECOND_APPEND_APPLY, this.User.Id))
- 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")
- //取出审批列表
- certSrv := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
- var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend
- certSrv.GetEntityById(certappendId, &supplierCertAppendEntity)
- 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 := ""
- if supplierCertAppendEntity.WorkFlowId == "0" || len(supplierCertAppendEntity.WorkFlowId) <= 0 {
- //启动工作流
- businessKey = certappendId + "-" + strconv.Itoa(supplierCertAppendEntity.AuditIndex)
- if this.User.IsCompanyUser == 1 {
- if supplierCertAppendEntity.InStyle == "2" {
- processInstanceId = svcActiviti.StartProcess(workflow.OIL_FIRST_ENUSER_APPEND_APPLY, businessKey, this.User.Id)
- } else if supplierCertAppendEntity.InStyle == "3" {
- processInstanceId = svcActiviti.StartProcess(workflow.OIL_SECOND_ENUSER_APPEND_APPLY, businessKey, this.User.Id)
- } else {
- processInstanceId = svcActiviti.StartProcess(workflow.OIL_ENUSER_APPEND_APPLY, businessKey, this.User.Id)
- }
- }else if this.User.IsCompanyUser == 0 {
- if supplierCertAppendEntity.InStyle == "2" {
- processInstanceId = svcActiviti.StartProcess(workflow.OIL_FIRST_APPEND_APPLY, businessKey, this.User.Id)
- }else if supplierCertAppendEntity.InStyle == "3" {
- processInstanceId = svcActiviti.StartProcess(workflow.OIL_SECOND_APPEND_APPLY, businessKey, this.User.Id)
- }else {
- processInstanceId = svcActiviti.StartProcess(workflow.OIL_APPEND_APPLY, businessKey, this.User.Id)
- }
- }
- }
- var ActiComplete workflow.ActiCompleteVM
- if this.User.IsCompanyUser == 1 {
- if supplierCertAppendEntity.InStyle == "2" {
- ActiComplete.ProcessKey = workflow.OIL_FIRST_ENUSER_APPEND_APPLY
- } else if supplierCertAppendEntity.InStyle == "3" {
- ActiComplete.ProcessKey = workflow.OIL_SECOND_ENUSER_APPEND_APPLY
- } else {
- ActiComplete.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY
- }
- }else if this.User.IsCompanyUser == 0 {
- if supplierCertAppendEntity.InStyle == "2" {
- ActiComplete.ProcessKey = workflow.OIL_FIRST_APPEND_APPLY
- }else if supplierCertAppendEntity.InStyle == "3" {
- ActiComplete.ProcessKey = workflow.OIL_SECOND_APPEND_APPLY
- }else{
- ActiComplete.ProcessKey = workflow.OIL_APPEND_APPLY
- }
- }
- ActiComplete.BusinessKey = businessKey
- ActiComplete.UserNames = firstAudit
- ActiComplete.UserId = this.User.Id
- ActiComplete.Result = "1"
- ActiComplete.Remarks = AuditRemark
- ActiComplete.CallbackUrl = ""
- receiveVal := svcActiviti.TaskComplete(ActiComplete)
- if receiveVal == "true" {
- if supplierCertAppendEntity.AuditIndex > 0 {
- // 审批历史
- var audithistoryentity audithistory.Base_AuditHistory
- audithistoryentity.EntityId, _ = strconv.Atoi(certappendId)
- audithistoryentity.WorkflowId = historworkflowid
- audithistoryentity.Process = workflow.OIL_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 审批
- // @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 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
- step = 2
- 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))
- var userlist []userRole.Base_User
- var setting auditsetting.Base_OilAuditSetting
- usvc := userRole.GetUserService(utils.DBE)
- if supplierCertAppendEntity.InStyle == "2" {
- 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 {
- 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, ",")
- step = 2
- backstatus = suppliercert.NO_SECOND_TRIAL_STATUS
- } 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" {
- supplierCertAppendEntity.Status = status
- supplierCertAppendEntity.Step = step
- cols := []string{
- "Status",
- "Step",
- }
- svc.UpdateEntityByIdCols(appendId, supplierCertAppendEntity, cols)
- if supplierCertAppendEntity.Status == "5" {
- if supplierCertAppendEntity.InStyle == "1" {
- paysvc := paymentinfo.GetPaymentService(utils.DBE)
- var Amount float64
- if supplierCertAppendEntity.AppendType == "01" {
- Amount = 6000
- } else if supplierCertAppendEntity.AppendType == "02" {
- Amount = 7000
- } else if supplierCertAppendEntity.AppendType == "03" {
- Amount = 8000
- }
- var payinfo paymentinfo.OilPaymentInfo
- payinfo.SupplierId = supplierCertAppendEntity.SupplierId
- payinfo.SupplierCertId = supplierCertAppendEntity.SupplierCertId
- payinfo.PayType = "3"
- payinfo.IsPay = "1"
- payinfo.Amount = strconv.FormatFloat(Amount,'E',-1,64)
- payinfo.CreateUserId = supplierCertAppendEntity.CreateUserId
- payinfo.CreateBy = supplierCertAppendEntity.CreateBy
- payinfo.CreateOn = time.Now()
- paysvc.InsertEntity(&payinfo)
- //paysvc.AddPaymentinfo(supplierCertAppendEntity.SupplierId, supplierCertAppendEntity.Id, Amount, "3")
- }
- }
- 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 = "-1"
- supplierCertAppendEntity.Status = "0"
- supplierCertAppendEntity.Step = 1
- supplierCertAppendEntity.AuditIndex = supplierCertAppendEntity.AuditIndex + 1
- }
- cols := []string{
- "Status",
- "Step",
- "AuditIndex",
- }
- _,err := svc.UpdateEntityByIdCols(appendId, supplierCertAppendEntity, cols)
- 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
- }
- }
- }
|