package oilsupplier import ( "dashoo.cn/backend/api/business/oilsupplier/annualaudit" "dashoo.cn/backend/api/business/oilsupplier/infochange" "dashoo.cn/backend/api/business/oilsupplier/supplier" "dashoo.cn/backend/api/business/oilsupplier/suppliercertappend" "dashoo.cn/backend/api/business/register" "dashoo.cn/backend/api/business/todolist" "dashoo.cn/backend/api/business/workflow" . "dashoo.cn/backend/api/controllers" "dashoo.cn/utils" "fmt" "sort" "strconv" "strings" "time" ) type TodoListController struct { BaseController } // @Title 获取列表 // @Description get user by token // @Success 200 {object} []supplier.OilSupplierView // @router /gettodolist [get] func (this *TodoListController) GetMyTaskEntityList() { page := this.GetPageInfoForm() stype := this.GetString("Type") // 1 准入 2 增项 3 年审 4 信息变更 5 注册 6 待入库 supplierTypeCode := this.GetString("SupplierTypeCode") supplierName := this.GetString("SupplierName") wfNames := "" if stype == "1" { wfNames = workflow.OIL_FIRST_ENUSER_SUPPLIER_APPLY + "," + workflow.OIL_ENUSER_SUPPLIER_APPLY + "," + workflow.OIL_SECOND_ENUSER_SUPPLIER_APPLY + "," + workflow.OIL_SUPPLIER_INSTORE + "," + workflow.OIL_SECOND_OTHER_SUPPLIER_APPLY } else if stype == "2" { wfNames = workflow.OIL_ENUSER_APPEND_APPLY + "," + workflow.OIL_FIRST_ENUSER_APPEND_APPLY + "," + workflow.OIL_SECOND_ENUSER_APPEND_APPLY + "," + workflow.OIL_SECOND_OTHER_APPEND_APPLY } else if stype == "3" { wfNames = workflow.OIL_AUDIT_APPLY } else if stype == "4" { wfNames = workflow.OIL_INFO_CHANGE } else if stype == "5" { wfNames = workflow.OIL_REGISTER_APPLY } else if stype == "6" { wfNames = workflow.OIL_SUPPLIER_INSTORE } var todoliststemp []todolist.TodoList var pagingResult workflow.ActiMyPagingResultVM var myTasksRetWithTimes []workflow.ActiMyTasksRetWithTimeVM actisvc := workflow.GetActivitiService(utils.DBE) pagingResult = actisvc.GetMyAllTypePagingTasksWithTime(this.User.Id, page.CurrentPage, page.Size, wfNames, supplierTypeCode, supplierName) myTasksRetWithTimes = pagingResult.TaskList //取出各种类型的ID for _,item := range myTasksRetWithTimes { idx := strings.Index(item.BusinessKey, "-") id := item.BusinessKey if idx >= 0 { id = strings.Split(item.BusinessKey, "-")[0] } //工作流名称 has := false wfName := strings.Split(item.ProcessDefinitionId, ":")[0] //如:oil_enuser_supplier_apply:2:2543 if (item.TaskName != "集中评审") && (wfName == workflow.OIL_FIRST_ENUSER_SUPPLIER_APPLY || wfName == workflow.OIL_ENUSER_SUPPLIER_APPLY || wfName == workflow.OIL_SECOND_ENUSER_SUPPLIER_APPLY || wfName == workflow.OIL_SUPPLIER_INSTORE || wfName == workflow.OIL_SECOND_OTHER_SUPPLIER_APPLY) { //准入 where := " 1=1 " where = where + " and b.Id = '" + id + "'" var todo todolist.TodoList svc := supplier.GetOilSupplierService(utils.DBE) has = svc.GetMyTodoEntitie(OilSupplierName, OilSupplierCertName, &todo, where) if has { todo.Type = todolist.SUPPLIER todo.UserName = this.User.Realname todo.CreateTime = item.CreateTime todo.TaskName = item.TaskName if wfName == workflow.OIL_SUPPLIER_INSTORE { todo.Type = todolist.STORAGE } todoliststemp = append(todoliststemp, todo) } } else if (item.TaskName != "增项-集中评审") && (wfName == workflow.OIL_ENUSER_APPEND_APPLY || wfName == workflow.OIL_FIRST_ENUSER_APPEND_APPLY || wfName == workflow.OIL_SECOND_ENUSER_APPEND_APPLY || wfName == workflow.OIL_SECOND_OTHER_APPEND_APPLY) { //增项 where := " 1=1 " where = where + " and b.Id = '" + id + "'" var todo todolist.TodoList svcapp := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) has :=svcapp.GetTodoEntitie(OilSupplierName, OilSupplierCertAppendName, &todo, where) if has { todo.Type = todolist.CERTAPPEND todo.TaskName = item.TaskName todo.UserName = this.User.Realname todo.CreateTime = item.CreateTime todoliststemp = append(todoliststemp, todo) } } else if wfName == workflow.OIL_AUDIT_APPLY { //年审 var todo todolist.TodoList var listannu annualaudit.OilAnnualAudit svc := annualaudit.GetOilAnnualAuditService(utils.DBE) has = svc.GetEntityById(id, &listannu) if has { todo.Id = listannu.Id todo.SupplierId = strconv.Itoa(listannu.SupplierId) todo.Type = todolist.ANNUALAUDIT todo.SupplierName = listannu.SupplierName todo.UserName = this.User.Realname todo.TaskName = item.TaskName todo.SupplierTypeCode = listannu.SupplierTypeName todo.Step = strconv.Itoa(listannu.Step) todo.Status = listannu.Status todo.CertId = strconv.Itoa(listannu.CerId) todo.CreateTime = item.CreateTime todoliststemp = append(todoliststemp, todo) } } else if wfName == workflow.OIL_INFO_CHANGE { //资质变更 var todo todolist.TodoList var listInfo infochange.OilInfoChange svc := infochange.GetInfoChangeService(utils.DBE) has = svc.GetEntityById(id, &listInfo) if has { todo.Id = listInfo.Id todo.Type = todolist.INFOCHANGE todo.SupplierId = strconv.Itoa(listInfo.SupplierId) todo.SupplierName = listInfo.SupplierName todo.UserName = this.User.Realname todo.TaskName = item.TaskName todo.SupplierTypeCode = listInfo.SupplierTypeName todo.Status = listInfo.Status todo.CreateTime = item.CreateTime todoliststemp = append(todoliststemp, todo) } } else if wfName == workflow.OIL_REGISTER_APPLY { //企业用户注册 var todo todolist.TodoList regsvc := register.GetOilCorporateInfoService(utils.DBE) var listinfo register.OilCorporateInfo has = regsvc.GetEntityById(id, &listinfo) if has { todo.Id = listinfo.Id todo.Type = todolist.REGISTER todo.SupplierName = listinfo.SupplierName todo.UserName = this.User.Realname todo.TaskName = item.TaskName todo.Status = strconv.Itoa(listinfo.CheckStatus) todo.CreateTime = item.CreateTime todoliststemp = append(todoliststemp, todo) } } } var todolists []todolist.TodoList CreateOn := this.GetString("CreateOn") if CreateOn != "" { dates := strings.Split(CreateOn, ",") var minDate time.Time var maxDate time.Time if len(dates) == 2 { minDate,_ = utils.TimeParse(dates[0], "2006-01-02 15:04") maxDate,_ = utils.TimeParse(dates[1], "2006-01-02 15:04") } for i := 0; i < len(todoliststemp); i++ { fmt.Println(minDate.Unix()*1000, "==",maxDate.Unix()*1000) fmt.Println(todoliststemp[i].CreateTime, "==",todoliststemp[i].CreateTime) if todoliststemp[i].CreateTime > minDate.Unix()*1000 && todoliststemp[i].CreateTime < maxDate.Unix()*1000 { todolists = append(todolists, todoliststemp[i]) } } } else { todolists = todoliststemp } sort.Slice(todolists, func(i, j int) bool { return todolists[i].CreateTime > todolists[j].CreateTime }) var datainfo DataInfo datainfo.Items = todolists datainfo.CurrentItemCount = pagingResult.Total datainfo.PageIndex = page.CurrentPage datainfo.ItemsPerPage = page.Size this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取已办列表 // @Description get user by token // @Success 200 {object} []supplier.OilSupplierView // @router /getmytaskfinishedlist [get] func (this *TodoListController) GetMyTaskFinishedList() { page := this.GetPageInfoForm() stype := this.GetString("Type") supplierTypeCode := this.GetString("SupplierTypeCode") supplierName := this.GetString("SupplierName") wfNames := "" if stype == "1" { wfNames = workflow.OIL_FIRST_ENUSER_SUPPLIER_APPLY + "," + workflow.OIL_ENUSER_SUPPLIER_APPLY + "," + workflow.OIL_SECOND_ENUSER_SUPPLIER_APPLY + "," + workflow.OIL_SUPPLIER_INSTORE } else if stype == "2" { wfNames = workflow.OIL_ENUSER_APPEND_APPLY + "," + workflow.OIL_FIRST_ENUSER_APPEND_APPLY + "," + workflow.OIL_SECOND_ENUSER_APPEND_APPLY } else if stype == "3" { wfNames = workflow.OIL_AUDIT_APPLY } else if stype == "4" { wfNames = workflow.OIL_INFO_CHANGE } else if stype == "5" { wfNames = workflow.OIL_REGISTER_APPLY } else if stype == "6" { wfNames = workflow.OIL_SUPPLIER_INSTORE } var todoliststemp []todolist.TodoList var pagingResult workflow.ActiMyPagingResultVM var myTasksRetWithTimes []workflow.ActiMyTasksRetWithTimeVM actisvc := workflow.GetActivitiService(utils.DBE) pagingResult = actisvc.GetMyAllTypePagingFinishedTasksWithTime(this.User.Id, page.CurrentPage, page.Size, wfNames, supplierTypeCode, supplierName) myTasksRetWithTimes = pagingResult.TaskList //取出各种类型的ID for _,item := range myTasksRetWithTimes { idx := strings.Index(item.BusinessKey, "-") id := item.BusinessKey if idx >= 0 { id = strings.Split(item.BusinessKey, "-")[0] } //工作流名称 has := false wfName := strings.Split(item.ProcessDefinitionId, ":")[0] //如:oil_enuser_supplier_apply:2:2543 if wfName == workflow.OIL_FIRST_ENUSER_SUPPLIER_APPLY || wfName == workflow.OIL_ENUSER_SUPPLIER_APPLY || wfName == workflow.OIL_SECOND_ENUSER_SUPPLIER_APPLY || wfName == workflow.OIL_SUPPLIER_INSTORE { //准入 where := " 1=1 " where = where + " and b.Id = '" + id + "'" var todo todolist.TodoList svc := supplier.GetOilSupplierService(utils.DBE) has = svc.GetMyTodoEntitie(OilSupplierName, OilSupplierCertName, &todo, where) if has { todo.Type = todolist.SUPPLIER todo.UserName = this.User.Realname todo.CreateTime = item.CreateTime todo.TaskName = item.TaskName todoliststemp = append(todoliststemp, todo) } } else if wfName == workflow.OIL_ENUSER_APPEND_APPLY || wfName == workflow.OIL_FIRST_ENUSER_APPEND_APPLY || wfName == workflow.OIL_SECOND_ENUSER_APPEND_APPLY { //增项 where := " 1=1 " where = where + " and b.Id = '" + id + "'" var todo todolist.TodoList svcapp := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE) has :=svcapp.GetTodoEntitie(OilSupplierName, OilSupplierCertAppendName, &todo, where) if has { todo.TaskName = item.TaskName todo.Type = todolist.CERTAPPEND todo.UserName = this.User.Realname todo.CreateTime = item.CreateTime todoliststemp = append(todoliststemp, todo) } } else if wfName == workflow.OIL_AUDIT_APPLY { //年审 where := " 1=1 " where = where + " and Id = '" + id + "'" var todo todolist.TodoList var listannu annualaudit.OilAnnualAudit svc := annualaudit.GetOilAnnualAuditService(utils.DBE) has = svc.GetEntity(&listannu, where) if has { todo.Id = listannu.Id todo.SupplierId = strconv.Itoa(listannu.SupplierId) todo.Type = todolist.ANNUALAUDIT todo.SupplierName = listannu.SupplierName todo.UserName = this.User.Realname todo.TaskName = item.TaskName todo.SupplierTypeCode = listannu.SupplierTypeName todo.Step = strconv.Itoa(listannu.Step) todo.Status = listannu.Status todo.CertId = strconv.Itoa(listannu.CerId) todo.CreateTime = item.CreateTime todoliststemp = append(todoliststemp, todo) } } else if wfName == workflow.OIL_INFO_CHANGE { //资质变更 where := " 1=1 " where = where + " and Id = '" + id + "'" var todo todolist.TodoList var listInfo infochange.OilInfoChange svc := infochange.GetInfoChangeService(utils.DBE) has = svc.GetEntity(&listInfo, where) if has { todo.Id = listInfo.Id todo.Type = todolist.INFOCHANGE todo.SupplierId = strconv.Itoa(listInfo.SupplierId) todo.SupplierName = listInfo.SupplierName todo.UserName = this.User.Realname todo.TaskName = item.TaskName todo.SupplierTypeCode = listInfo.SupplierTypeName todo.Status = listInfo.Status todo.CreateTime = item.CreateTime todoliststemp = append(todoliststemp, todo) } } else if wfName == workflow.OIL_REGISTER_APPLY { //企业用户注册 var todo todolist.TodoList regsvc := register.GetOilCorporateInfoService(utils.DBE) var listinfo register.OilCorporateInfo has = regsvc.GetEntityById(id, &listinfo) if has { todo.Id = listinfo.Id todo.Type = todolist.REGISTER todo.SupplierName = listinfo.SupplierName todo.UserName = this.User.Realname todo.TaskName = item.TaskName todo.Status = strconv.Itoa(listinfo.CheckStatus) todo.CreateTime = item.CreateTime todoliststemp = append(todoliststemp, todo) } } } var todolists []todolist.TodoList CreateOn := this.GetString("CreateOn") if CreateOn != "" { dates := strings.Split(CreateOn, ",") var minDate time.Time var maxDate time.Time if len(dates) == 2 { minDate,_ = utils.TimeParse(dates[0], "2006-01-02 15:04") maxDate,_ = utils.TimeParse(dates[1], "2006-01-02 15:04") } for i := 0; i < len(todoliststemp); i++ { if todoliststemp[i].CreateTime > minDate.Unix()*1000 && todoliststemp[i].CreateTime < maxDate.Unix()*1000 { todolists = append(todolists, todoliststemp[i]) } } } else { todolists = todoliststemp } sort.Slice(todolists, func(i, j int) bool { return todolists[i].CreateTime > todolists[j].CreateTime }) var datainfo DataInfo datainfo.Items = todolists datainfo.CurrentItemCount = pagingResult.Total datainfo.PageIndex = page.CurrentPage datainfo.ItemsPerPage = page.Size this.Data["json"] = &datainfo this.ServeJSON() }