package oilcontract import ( "dashoo.cn/backend/api/business/auditsetting" "dashoo.cn/backend/api/business/oilcontract/contract" "dashoo.cn/backend/api/business/oilcontract/contractEvaluationItems" "dashoo.cn/backend/api/business/oilsupplier/supplier" "dashoo.cn/backend/api/business/organize" "dashoo.cn/business2/permission" "log" "sync" "dashoo.cn/backend/api/business/baseUser" "dashoo.cn/backend/api/business/oilcontract/contractReview" "dashoo.cn/backend/api/business/oilsupplier/suppliercert" "dashoo.cn/backend/api/business/workflow" "encoding/json" "fmt" "strconv" "strings" "time" // "dashoo.cn/backend/api/business/items" . "dashoo.cn/backend/api/controllers" "dashoo.cn/business2/userRole" "dashoo.cn/utils" ) type OilContractReviewController struct { BaseController } // @Title 获取列表 // @Description get user by token // @Success 200 {object} []contractReview.OilContractReviewWorkFlow // @router /list [get] func (this *OilContractReviewController) GetEntityList() { //获取分页信息 page := this.GetPageInfoForm() where := " 1=1 " orderby := "r.Id" asc := " desc " Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = Prop if Order == "asc" { asc = " asc " } } Id := this.GetString("Id") ContractClass := this.GetString("ContractClass") ContractName := this.GetString("ContractName") ProjectOwner := this.GetString("ProjectOwner") Telephone := this.GetString("Telephone") ContractNo := this.GetString("ContractNo") ContractId := this.GetString("ContractId") WorkflowId := this.GetString("WorkflowId") BusinessKey := this.GetString("BusinessKey") ProcessKey := this.GetString("ProcessKey") BackRemark := this.GetString("BackRemark") CreateOn := this.GetString("CreateOn") CreateOn1 := this.GetString("CreateOn1") SupplierName := this.GetString("SupplierName") SecondUnit := this.GetString("SecondUnit") PerformStatus := this.GetString("PerformStatus") Status := this.GetString("Status") Year := this.GetString("Year") Amount := this.GetString("Amount") IsAll := this.GetString("IsAll") if Id != "" { where = where + " and r.Id like '%" + Id + "%'" } if PerformStatus != "" { where = where + " and c.Status=" + PerformStatus + " " } if Amount != "" { where = where + " and c.Amount like '%" + Amount + "%'" } if ContractClass != "" { where = where + " and c.ContractClass = '" + ContractClass + "'" } if ProjectOwner != "" { where = where + " and c.ProjectOwner like '%" + ProjectOwner + "%'" } if Telephone != "" { where = where + " and c.Telephone like '%" + Telephone + "%'" } if ContractId != "" { where = where + " and r.ContractId = '" + ContractId + "'" } if WorkflowId != "" { where = where + " and r.WorkflowId like '%" + WorkflowId + "%'" } if BusinessKey != "" { where = where + " and r.BusinessKey like '%" + BusinessKey + "%'" } if ProcessKey != "" { where = where + " and r.ProcessKey like '%" + ProcessKey + "%'" } if BackRemark != "" { where = where + " and r.BackRemark like '%" + BackRemark + "%'" } if SupplierName != "" { where = where + " and c.SupplierName like '%" + SupplierName + "%'" } if ContractName != "" { where = where + " and c.ContractName like '%" + ContractName + "%'" } if ContractNo != "" { where = where + " and c.ContractNo like '%" + ContractNo + "%'" } if SecondUnit != "" { where = where + " and r.UnitId = " + SecondUnit } if Status != "" { where = where + " and r.Status=" + Status } if CreateOn != "" { dates := strings.Split(CreateOn, ",") if len(dates) == 2 { minDate := dates[0] maxDate := dates[1] where = where + " and r.CreateOn>='" + minDate + "' and r.CreateOn<='" + maxDate + "'" } } if CreateOn1 != "" { dates := strings.Split(CreateOn1, ",") if len(dates) == 2 { minDate := dates[0] maxDate := dates[1] where = where + " and c.StartDate>='" + minDate + "' and c.EndDate<='" + maxDate + "'" } } if Year != "" { where = where + " and r.CreateOn>='" + Year + "-01-01 00:00:00' and r.CreateOn<='" + Year + "-12-31 23:59:59' " } //超级管理员和有查看所有数据权限的用户不加条件 svcPerm := permission.GetPermissionService(utils.DBE) isauth := svcPerm.IsAuthorized(this.User.Id, "oil_contract.Review.AllRecord") if !isauth { // 是否查看本部门的 if IsAll == "" { //根据工作流查找 //集中评审相关人可看数据 actisvc := workflow.GetActivitiService(utils.DBE) //找出待办任务===准入 var certIdList string ids := actisvc.GetMyTasks(workflow.OIL_DAILY_CONTRACT_EVALUATION, this.User.Id) ids1 := actisvc.GetMyTasks(workflow.OIL_DAILY_CONTRACT_EVA_BY_BUSINESS, this.User.Id) ids += "," + ids1 if len(strings.Trim(ids, ",")) > 0 { certIdList += strings.Trim(ids, ",") + "," } certIdList = strings.Trim(certIdList, ",") certIdarr := strings.Split(certIdList, ",") for i, item := range certIdarr { idx := strings.Index(item, "-") if idx >= 0 { certIdarr[i] = strings.Split(item, "-")[0] } } certIdList = strings.Join(certIdarr, ",") if certIdList != "" { where += " and ( r.Id in (" + certIdList + ")" + " or r.CreateUserId = '" + this.User.Id + "')" } else { where = where + " and r.CreateUserId = '" + this.User.Id + "'" } } else { // 权限过滤 自己创建的评价 ,同二级部门创建的评价 ,企管法规处能看 where = where + " and ( r.CreateUserId = '" + this.User.Id + "' " where = where + " or r.UnitId = '" + strconv.Itoa(this.User.UnitId) + "' " where = where + " )" } } svc := contractReview.GetOilContractReviewService(utils.DBE) var list []contractReview.OilContractReviewListVo total := svc.GetContractReviewList(page.CurrentPage, page.Size, orderby, asc, &list, where) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total datainfo.PageIndex = page.CurrentPage datainfo.ItemsPerPage = page.Size this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取字典列表 // @Description get user by token // @Success 200 {object} map[string]interface{} // @router /dictlist [get] func (this *OilContractReviewController) GetDictList() { dictList := make(map[string]interface{}) //dictSvc := items.GetItemsService(utils.DBE) userSvc := baseUser.GetBaseUserService(utils.DBE) //customerSvc := svccustomer.GetCustomerService(utils.DBE) //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", this.User.AccCode) var userEntity userRole.Base_User userSvc.GetEntityById(this.User.Id, &userEntity) dictList["Supervisers"] = userSvc.GetUserListByDepartmentId(this.User.AccCode, userEntity.Departmentid) //var dictCustomer []svccustomer.Customer //customerSvc.GetEntitysByWhere(this.User.AccCode + CustomerName, "", &dictCustomer) //dictList["EntrustCorp"] = &dictCustomer var datainfo DataInfo datainfo.Items = dictList this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取实体 // @Description 获取实体 // @Success 200 {object} contractReview.OilContractReviewWorkFlow // @router /get/:id [get] func (this *OilContractReviewController) GetEntity() { Id := this.Ctx.Input.Param(":id") var model contractReview.OilContractReview svc := contractReview.GetOilContractReviewService(utils.DBE) svc.GetEntityByIdBytbl(OilContractReviewName, Id, &model) this.Data["json"] = &model this.ServeJSON() } // @Title 添加 // @Description 新增 // @Param body body contractReview.OilContractReviewWorkFlow // @Success 200 {object} controllers.Request // @router /add [post] func (this *OilContractReviewController) AddEntity() { var modeVO contractReview.OilContractReviewVo var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &modeVO) svc := contractReview.GetOilContractReviewService(utils.DBE) itemSvc := contractEvaluationItems.GetOilContractEvaluationItemsService(utils.DBE) var reviewMode contractReview.OilContractReview reviewMode.IsFinal = modeVO.IsFinal reviewMode.IsBusiness = modeVO.IsBusiness reviewMode.ContractId = modeVO.ContractId reviewMode.Status = "0" reviewMode.Unit = this.User.Unit reviewMode.UnitId = this.User.UnitId reviewMode.CreateOn = time.Now() reviewMode.CreateBy = this.User.Realname reviewMode.CreateUserId, _ = utils.StrTo(this.User.Id).Int() _, err := svc.InsertEntityBytbl(OilContractReviewName, &reviewMode) var items2 []contractEvaluationItems.OilContractEvaluationItems var items3 []contractEvaluationItems.OilContractEvaluationItems var items4 []contractEvaluationItems.OilContractEvaluationItems // 业务处室发起评价 // 新增配置项 for i, v := range modeVO.Items { fmt.Print(i) var temp2 contractEvaluationItems.OilContractEvaluationItems temp2.ContentReviewId = reviewMode.Id temp2.Type = v.Category temp2.Category = 0 temp2.ItemId = v.Id temp2.ParentId = v.ParentId temp2.SequenceNo = v.SequenceNo temp2.Content = v.Content temp2.NormalScore = v.NormalScore temp2.Score = v.Score temp2.Value = v.Value temp2.LevelCode = v.LevelCode temp2.Remark = v.Remark temp2.Content = v.Content temp2.ModifiedOn = time.Now() temp2.ModifiedBy = this.User.Realname temp2.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() items2 = append(items2, temp2) var temp3 contractEvaluationItems.OilContractEvaluationItems temp3.ContentReviewId = reviewMode.Id temp3.Type = v.Category temp3.Category = 1 temp3.ItemId = v.Id temp3.ParentId = v.ParentId temp3.SequenceNo = v.SequenceNo temp3.Content = v.Content temp3.NormalScore = v.NormalScore temp3.Score = v.Score temp3.Value = v.Value temp3.LevelCode = v.LevelCode temp3.Remark = v.Remark temp3.Content = v.Content temp3.ModifiedOn = time.Now() temp3.ModifiedBy = this.User.Realname temp3.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() items3 = append(items3, temp3) // 保存专业处室发起评价 var temp4 contractEvaluationItems.OilContractEvaluationItems temp4.ContentReviewId = reviewMode.Id temp4.Type = v.Category temp4.Category = 2 temp4.ItemId = v.Id temp4.ParentId = v.ParentId temp4.SequenceNo = v.SequenceNo temp4.Content = v.Content temp4.NormalScore = v.NormalScore temp4.Score = v.Score temp4.Value = v.Value temp4.LevelCode = v.LevelCode temp4.Remark = v.Remark temp4.Content = v.Content temp4.ModifiedOn = time.Now() temp4.ModifiedBy = this.User.Realname temp4.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() items4 = append(items4, temp4) } errBool := true if modeVO.IsBusiness == 0 { _, err2 := itemSvc.DBE.Insert(items2) // 专业处室评价默认二级 _, err3 := itemSvc.DBE.Insert(items3) if err2 == nil && err3 == nil { errBool = false } } if modeVO.IsBusiness == 1 { _, err4 := itemSvc.DBE.Insert(items4) if err4 == nil { errBool = false } } var errinfo ErrorDataInfo if err == nil && errBool == false { //新增 errinfo.Message = "添加成功!" errinfo.Code = 0 errinfo.Item = reviewMode.Id this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 从数据录入数据导出到word文档 // @Description 数据存入word // @Success 200 {object} controllers.Request // @router /exportword/:id [get] func (this *OilContractReviewController) DocExport() { // 填物资类信息表首页信息 Id := this.Ctx.Input.Param(":id") var Url string var fileName string svcActiviti := workflow.GetActivitiService(utils.DBE) var model contractReview.OilContractReview svc := contractReview.GetOilContractReviewService(utils.DBE) var items []contractEvaluationItems.OilContractEvaluationItems var items1 []contractEvaluationItems.OilContractEvaluationItems itemSvc := contractEvaluationItems.GetOilContractEvaluationItemsService(utils.DBE) var contractModel contract.OilContract contractSvc := contract.GetOilContractService(utils.DBE) where := " Id = '" + Id + "'" svc.GetEntityByWhere(OilContractReviewName, where, &model) where3 := " Id= '" + utils.ToStr(model.ContractId) + "' " contractSvc.GetEntityByWhere(OilContractName, where3, &contractModel) var score = 0.00 var normalScore = 0.00 var count = 1.00 datamap := structToMapDemo(model) where2 := " b.ContentReviewId = " + Id + " AND a.Type = '" + contractModel.ContractClass + "'" itemSvc.GetSumScore(&items, where2) where2 = " ContentReviewId = " + Id itemSvc.GetCountItems(&items1, where2) if len(items1) == 2 { count += 1 } if items != nil { for i, v := range items { fmt.Print(i) fmt.Print(utils.ToStr(v.ItemId)) if v.Type == 1 { Score1, _ := strconv.ParseFloat(v.Score, 64) datamap["score_"+utils.ToStr(v.ItemId)] = Score1 / count datamap["content_"+utils.ToStr(v.ItemId)] = v.Remark if v.ParentId == 0 { score = score + (Score1 / count) normal, _ := strconv.ParseFloat(v.NormalScore, 64) normalScore = normalScore + (normal / count) } } else { datamap["bool_"+utils.ToStr(v.ItemId)] = If(v.Value == 1, "是", "否") } } } var supplierEntity supplier.OilSupplier supplierSvc := supplier.GetOilSupplierService(utils.DBE) supplierSvc.GetEntityByIdBytbl(OilSupplierName, contractModel.SupplierId, &supplierEntity) datamap["Score"] = utils.ToStr(score) datamap["Standard"] = utils.ToStr(normalScore) datamap["Discount"] = score if contractModel.Id != 0 { datamap["Amount"] = contractModel.Amount datamap["SupplierName"] = contractModel.SupplierName datamap["ProjectName"] = contractModel.ContractName datamap["ContractNo"] = contractModel.ContractNo datamap["SubPackage"] = If(contractModel.SubPackage == 1, "是", "否") if contractModel.ProjectType == "咨询" { datamap["ProjectType"] = "☑咨询 □勘察 □设计 □施工\n□监理 □检测 □工程总承包" } else if contractModel.ContractClass == "勘探" { datamap["ProjectType"] = "□咨询 ☑勘察 □设计 □施工\n□监理 □检测 □工程总承包" } else if contractModel.ContractClass == "设计" { datamap["ProjectType"] = "□咨询 □勘察 ☑设计 □施工\n□监理 □检测 □工程总承包" } else if contractModel.ContractClass == "施工" { datamap["ProjectType"] = "□咨询 □勘察 □设计 ☑施工\n□监理 □检测 □工程总承包" } datamap["ContractPeriod"] = contractModel.ContractPeriod datamap["OpenDate"] = contractModel.OpenDate.Format("2006年01月02日") datamap["PlanFinishDate"] = contractModel.PlanFinishDate.Format("2006年01月02日") datamap["ConstructionUnit"] = contractModel.ConstructionUnit datamap["ConstructionOwner"] = contractModel.ConstructionOwner datamap["ConstructionTelphone"] = contractModel.ConstructionTelphone } if supplierEntity.Id != 0 { if supplierEntity.Grade == "一级" { datamap["OperType"] = "☑一级供应商 □二级制造商 □二级贸易商 □代理商" } else if supplierEntity.OperType == "制造商" { datamap["OperType"] = "□一级供应商 ☑二级制造商 □二级贸易商 □代理商" } else if supplierEntity.OperType == "代理商" { datamap["OperType"] = "□一级供应商 □二级制造商 □二级贸易商 ☑代理商" } else if supplierEntity.OperType == "贸易商" { datamap["OperType"] = "□一级供应商 □二级制造商 ☑二级贸易商 □代理商" } } // 获取组织名称 svcorg := organize.GetOrganizeService(utils.DBE) datamap["DepartName"] = svcorg.GetNameById(strconv.Itoa(this.User.UnitId)) fileName = "" Url = "" if contractModel.ContractClass == "01" { fileName = "供应商日常业绩评价表模板.docx" Url = utils.Cfg.MustValue("workflow", "reviewGoodsUrl") } else if contractModel.ContractClass == "02" { fileName = "承包商日常业绩评价表模板.docx" Url = utils.Cfg.MustValue("workflow", "reviewBasisUrl") } else { if contractModel.ClassName == "供用水电气热合同" { datamap["OperType"] = "☑水电气热 □油田工程 □仓储保管\n□技术和知识产权 □运输 □服务\n□承揽 □租赁 □其他 " } else if contractModel.ClassName == "仓储保管合同" { datamap["OperType"] = "□水电气热 □油田工程 ☑仓储保管\n□技术和知识产权 □运输 □服务\n□承揽 □租赁 □其他 " } else if contractModel.ClassName == "技术合同和知识产权合同" { datamap["OperType"] = "□水电气热 □油田工程 □仓储保管\n☑技术和知识产权 □运输 □服务\n□承揽 □租赁 □其他 " } else if contractModel.ClassName == "运输合同" { datamap["OperType"] = "□水电气热 □油田工程 □仓储保管\n□技术和知识产权 ☑运输 □服务\n□承揽 □租赁 □其他 " } else if contractModel.ClassName == "服务合同" { datamap["OperType"] = "□水电气热 □油田工程 □仓储保管\n□技术和知识产权 □运输 ☑服务\n□承揽 □租赁 □其他 " } else if contractModel.ClassName == "承揽合同" { datamap["OperType"] = "□水电气热 □油田工程 □仓储保管\n□技术和知识产权 □运输 □服务\n☑承揽 □租赁 □其他 " } else if contractModel.ClassName == "租赁合同" { datamap["OperType"] = "□水电气热 □油田工程 □仓储保管\n□技术和知识产权 □运输 □服务\n□承揽 ☑租赁 □其他 " } else { datamap["OperType"] = "□水电气热 □油田工程 □仓储保管\n□技术和知识产权 □运输 □服务\n□承揽 □租赁 ☑其他 " } fileName = "服务商日常业绩评价表模板.docx" Url = utils.Cfg.MustValue("workflow", "reviewServiceUrl") } t := time.Now() datamap["CreateDate"] = t.Format("2006年01月02日") datamap["Year"] = t.Format("2006") datamap["Creater"] = this.User.Realname //datamap["TableComment"] = []string{"MajorEquipments", "ThreeYears", "Patent", "Winning"} retDocUrl := svcActiviti.FillWordTemplate(datamap, Url, fileName) //retDocUrl := svcActiviti.FillWordWatermarkTemplate(datamap, Url, fileName, model.SupplierName) var datainfo ErrorDataInfo datainfo.Code = 0 datainfo.Item = retDocUrl datainfo.Message = "导出成功" this.Data["json"] = &datainfo this.ServeJSON() } func If(condition bool, trueVal, falseVal interface{}) interface{} { if condition { return trueVal } return falseVal } // @Title 添加 // @Description 业务处室保存评价 // @Param body body contractReview.OilContractReviewWorkFlow // @Success 200 {object} controllers.Request // @router /save-sec-evaluation/:id [post] func (this *OilContractReviewController) SaveEvaluationItemsBySec() { id := this.Ctx.Input.Param(":id") var errinfo ErrorInfo if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var modeVO contractReview.OilContractReviewVo itemSvc := contractEvaluationItems.GetOilContractEvaluationItemsService(utils.DBE) var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &modeVO) where := "ContentReviewId=" + id + " AND Category = 1 " // 清除掉之前的 itemSvc.DeleteEntityBytbl(OilContractEvaluationItemsName, where) var items []contractEvaluationItems.OilContractEvaluationItems // 新增配置项 for i, v := range modeVO.Items { fmt.Print(i) var temp contractEvaluationItems.OilContractEvaluationItems temp.ContentReviewId, _ = strconv.Atoi(id) temp.Type = v.Type temp.Category = 1 temp.ItemId = v.ItemId temp.ParentId = v.ParentId temp.SequenceNo = v.SequenceNo temp.Content = v.Content temp.NormalScore = v.NormalScore temp.Score = v.Score temp.Value = v.Value temp.LevelCode = v.LevelCode temp.Remark = v.Remark temp.Content = v.Content temp.ModifiedOn = time.Now() temp.ModifiedBy = this.User.Realname temp.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() items = append(items, temp) } _, err := itemSvc.DBE.Insert(items) 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 企管法规处修改二级单位的评价内容 // @Param body body contractReview.OilContractReviewWorkFlow // @Success 200 {object} controllers.Request // @router /prof-update/:id [post] func (this *OilContractReviewController) ProfUpdateSecEvaEntity() { id := this.Ctx.Input.Param(":id") var errinfo ErrorInfo if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var modeVO contractReview.OilContractReviewVo itemSvc := contractEvaluationItems.GetOilContractEvaluationItemsService(utils.DBE) var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &modeVO) where := "ContentReviewId=" + id + " AND Category = 0 " // 清除掉之前的 itemSvc.DeleteEntityBytbl(OilContractEvaluationItemsName, where) var items []contractEvaluationItems.OilContractEvaluationItems // 新增配置项 for i, v := range modeVO.Items { fmt.Print(i) var temp contractEvaluationItems.OilContractEvaluationItems temp.ContentReviewId, _ = strconv.Atoi(id) temp.Type = v.Category //v.Type temp.ItemId = v.Id temp.Category = 0 temp.ParentId = v.ParentId temp.SequenceNo = v.SequenceNo temp.Content = v.Content temp.NormalScore = v.NormalScore temp.Score = v.Score temp.Value = v.Value temp.LevelCode = v.LevelCode temp.Remark = v.Remark temp.Content = v.Content temp.ModifiedOn = time.Now() temp.ModifiedBy = this.User.Realname temp.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() items = append(items, temp) } _, err := itemSvc.DBE.Insert(items) 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 修改实体 // @Param body body contractReview.OilContractReviewWorkFlow // @Success 200 {object} controllers.Request // @router /update/:id [post] func (this *OilContractReviewController) UpdateEntity() { id := this.Ctx.Input.Param(":id") var errinfo ErrorInfo if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var modeVO contractReview.OilContractReviewVo svc := contractReview.GetOilContractReviewService(utils.DBE) itemSvc := contractEvaluationItems.GetOilContractEvaluationItemsService(utils.DBE) var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &modeVO) var reviewMode contractReview.OilContractReview reviewMode.ContractId = modeVO.ContractId reviewMode.Status = "0" reviewMode.ModifiedOn = time.Now() reviewMode.ModifiedBy = this.User.Realname reviewMode.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() cols := []string{ "Id", "ContractId", "BackRemark", "FirstAudit", "SecondAudit", "ThirdAudit", "FourthAudit", "ProfessionalAudit", "AuditIndex", "IsFinal", "ModifiedOn", "ModifiedUserId", "ModifiedBy", } err := svc.UpdateEntityBytbl(OilContractReviewName, id, &reviewMode, cols) errBool := true if modeVO.IsBusiness == 0 { where := "ContentReviewId=" + id + " AND Category = 0 " // 清除掉之前的 itemSvc.DeleteEntityBytbl(OilContractEvaluationItemsName, where) var items []contractEvaluationItems.OilContractEvaluationItems // 新增配置项 for i, v := range modeVO.Items { fmt.Print(i) var temp contractEvaluationItems.OilContractEvaluationItems temp.ContentReviewId, _ = strconv.Atoi(id) temp.Type = v.Category //v.Type temp.ItemId = v.Id temp.Category = 0 temp.ParentId = v.ParentId temp.SequenceNo = v.SequenceNo temp.Content = v.Content temp.NormalScore = v.NormalScore temp.Score = v.Score temp.Value = v.Value temp.LevelCode = v.LevelCode temp.Remark = v.Remark temp.Content = v.Content temp.ModifiedOn = time.Now() temp.ModifiedBy = this.User.Realname temp.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() items = append(items, temp) } _, err2 := itemSvc.DBE.Insert(items) where2 := "ContentReviewId=" + id + " AND Category = 1 " // 清除掉之前的 itemSvc.DeleteEntityBytbl(OilContractEvaluationItemsName, where2) var items2 []contractEvaluationItems.OilContractEvaluationItems // 新增配置项 for i, v := range modeVO.Items { fmt.Print(i) var temp2 contractEvaluationItems.OilContractEvaluationItems temp2.ContentReviewId, _ = strconv.Atoi(id) temp2.Type = v.Category //v.Type temp2.ItemId = v.Id temp2.Category = 1 temp2.ParentId = v.ParentId temp2.SequenceNo = v.SequenceNo temp2.Content = v.Content temp2.NormalScore = v.NormalScore temp2.Score = v.Score temp2.Value = v.Value temp2.LevelCode = v.LevelCode temp2.Remark = v.Remark temp2.Content = v.Content temp2.ModifiedOn = time.Now() temp2.ModifiedBy = this.User.Realname temp2.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() items2 = append(items2, temp2) } _, err3 := itemSvc.DBE.Insert(items2) if err2 == nil && err3 == nil { errBool = false } } if modeVO.IsBusiness == 1 { where3 := "ContentReviewId=" + id + " AND Category = 2 " // 清除掉之前的 itemSvc.DeleteEntityBytbl(OilContractEvaluationItemsName, where3) var items3 []contractEvaluationItems.OilContractEvaluationItems // 新增配置项 for i, v := range modeVO.Items { fmt.Print(i) var temp3 contractEvaluationItems.OilContractEvaluationItems temp3.ContentReviewId, _ = strconv.Atoi(id) temp3.Type = v.Category //v.Type temp3.ItemId = v.Id temp3.Category = 2 temp3.ParentId = v.ParentId temp3.SequenceNo = v.SequenceNo temp3.Content = v.Content temp3.NormalScore = v.NormalScore temp3.Score = v.Score temp3.Value = v.Value temp3.LevelCode = v.LevelCode temp3.Remark = v.Remark temp3.Content = v.Content temp3.ModifiedOn = time.Now() temp3.ModifiedBy = this.User.Realname temp3.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() items3 = append(items3, temp3) } _, err4 := itemSvc.DBE.Insert(items3) if err4 == nil { errBool = false } } if err == nil && errBool == false { 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 *OilContractReviewController) DeleteEntity() { Id := this.Ctx.Input.Param(":Id") var errinfo ErrorInfo if Id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var model contractReview.OilContractReview var entityempty contractReview.OilContractReview svc := contractReview.GetOilContractReviewService(utils.DBE) // 评分审核是否结束校验 svc.GetEntityByIdBytbl(OilContractReviewName, Id, &model) if model.Status > "0" && model.Status < "8" { errinfo.Message = "该合同评价正在审核,不允许删除!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } var setting auditsetting.Base_OilAuditSetting orgSvc := organize.GetOrganizeService(utils.DBE) whereAudit := "AuditStepCode='PROF_REGULATION'" orgSvc.GetEntity(&setting, whereAudit) res := orgSvc.UserInRoleById(this.User.Id, strconv.Itoa(setting.RoleId)) if model.Status == "8" && !res { errinfo.Message = "无权删除!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } opdesc := "删除-" + Id err := svc.DeleteOperationAndWriteLogBytbl(OilContractReviewName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报") if err == nil { activitiService := workflow.GetActivitiService(utils.DBE) var deleteProcessVM workflow.DeleteProcessVM if model.WorkflowId != "" && model.WorkflowId != "0" { deleteProcessVM.ProcessInstanceId = model.WorkflowId if model.Status == "8" { deleteProcessVM.DeleteReason = "企管法规处删除日常评价" } else { 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 二级单位提交审批 // @Success 200 {object} controllers.Request // @router /unit-audit/:id [post] func (this *OilContractReviewController) UnitAuditEntity() { Id := 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 fmt.Println("2222222222") 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() } }() //取出日常评审主表信息 conRev := contractReview.GetOilContractReviewService(utils.DBE) var contractReviewEntity contractReview.OilContractReview conRev.GetEntityById(Id, &contractReviewEntity) if strconv.Itoa(contractReviewEntity.CreateUserId) != this.User.Id { panic("该评价创建人才可提交审核!") } //检查是否可提交 //conRev.IsSupplierCertCanSubmit(strconv.Itoa(supplierCertEntity.SupplierId), certId) //取出合同表 contractSvc := contract.GetOilContractService(utils.DBE) var contractEntity contract.OilContract contractSvc.GetEntityById(contractReviewEntity.ContractId, &contractEntity) svcActiviti := workflow.GetActivitiService(utils.DBE) //启动工作流 businessKey := contractReviewEntity.BusinessKey processInstanceId := contractReviewEntity.WorkflowId // 如果被驳回,不再新启工作流 if processInstanceId == "" { //启动工作流 businessKey = Id + "-" + strconv.Itoa(contractReviewEntity.AuditIndex) processInstanceId = svcActiviti.StartProcess2(workflow.OIL_DAILY_CONTRACT_EVALUATION, businessKey, this.User.Id, "1", contractEntity.ContractClass, contractEntity.SupplierName) if len(processInstanceId) <= 0 { panic("工作流启动失败!") } contractReviewEntity.AuditIndex += 1 } // 将启动和工作流,选择的初审和复审人员保存下来 cols := []string{ "Id", "FirstAudit", "SecondAudit", "thirdAudit", "WorkflowId", "BusinessKey", "ProcessKey", "CommitComId", "AuditIndex", } contractReviewEntity.ProcessKey = workflow.OIL_DAILY_CONTRACT_EVALUATION contractReviewEntity.BusinessKey = businessKey contractReviewEntity.WorkflowId = processInstanceId contractReviewEntity.FirstAudit, _ = strconv.Atoi(firstAudit) contractReviewEntity.SecondAudit, _ = strconv.Atoi(secondAudit) contractReviewEntity.ThirdAudit, _ = strconv.Atoi(thirdAudit) contractReviewEntity.CommitComId = strconv.Itoa(unitId) conRev.UpdateEntityByIdCols(Id, contractReviewEntity, cols) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_DAILY_CONTRACT_EVALUATION ActiComplete.BusinessKey = contractReviewEntity.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" { panic("工作流异常,请联系管理员!" + receiveVal) } } // @Title 分办之后的各级审批 --审批 包含:二级单位初审、复审, 业务处室专业审核、企管法规处审核 // @Description 分办之后的各级审批 // @Success 200 {object} controllers.Request // @router /common-audit/:id [post] func (this *OilContractReviewController) CommonAuditEntity() { Id := this.Ctx.Input.Param(":id") result := this.GetString("result") AuditRemark := this.GetString("AuditRemark") var errinfo ErrorDataInfo if Id == "" { errinfo.Message = "请至少选择一条申请进行审批!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } Ids := strings.Split(Id, ",") defer func() { //finally处理失败的异常 if err := recover(); err != nil { errinfo.Message = err.(string) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } else { //返回正确结果 msg := "" if len(Ids) > 1 { msg = "审核提交成功,请耐心等待批处理结果!" } else { msg = "审批成功!" } if result == "1" { errinfo.Message = msg } else { errinfo.Message = "审批驳回成功!" } errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } }() var lock sync.Mutex for i := 0; i < len(Ids); i++ { lock.Lock() //取出日常评审主表信息 conRev := contractReview.GetOilContractReviewService(utils.DBE) var contractReviewEntity contractReview.OilContractReview conRev.GetEntityById(Ids[i], &contractReviewEntity) svcActiviti := workflow.GetActivitiService(utils.DBE) var ActiComplete workflow.ActiCompleteVM if contractReviewEntity.IsBusiness == 1 { ActiComplete.ProcessKey = workflow.OIL_DAILY_CONTRACT_EVA_BY_BUSINESS // 业务处室分办提交的日常评价 } else { ActiComplete.ProcessKey = workflow.OIL_DAILY_CONTRACT_EVALUATION // 二级单位提交的日常评价 } ActiComplete.BusinessKey = contractReviewEntity.BusinessKey ActiComplete.UserId = this.User.Id //审批人员 ActiComplete.Result = result //前台审批[同意、不同意] ActiComplete.Remarks = AuditRemark ActiComplete.CallbackUrl = utils.Cfg.MustValue("workflow", "callbackHost") if len(Ids) > 1 { go func() { receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { log.Print("日常评价 工作流异常,业务ID:" + contractReviewEntity.BusinessKey + ",工作流信息:" + receiveVal) } }() } else { receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { log.Print("日常评价 工作流异常,业务ID:" + contractReviewEntity.BusinessKey + ",工作流信息:" + receiveVal) } } lock.Unlock() } } // @Title 业务处室接收分办 // @Description 业务处室接收分办 // @Success 200 {object} controllers.Request // @router /business-separate-audit/:id [post] func (this *OilContractReviewController) BusinessOfficeSeparateAuditEntity() { Id := this.Ctx.Input.Param(":id") Result := this.GetString("Result") ProfessionalAudit := this.GetString("ProfessionalAudit") AuditRemark := this.GetString("AuditRemark") var errInfo ErrorDataInfo if Id == "" { errInfo.Message = "请至少选择一条申请进行审批!" errInfo.Code = -1 this.Data["json"] = &errInfo this.ServeJSON() return } Ids := strings.Split(Id, ",") defer func() { //finally处理失败的异常 if err := recover(); err != nil { errInfo.Message = err.(string) errInfo.Code = -1 this.Data["json"] = &errInfo this.ServeJSON() } else { //返回正确结果 msg := "" if len(Ids) > 1 { msg = "审核提交成功,请耐心等待批处理结果!" } else { msg = "审批成功!" } if Result == "1" { errInfo.Message = msg } else { errInfo.Message = "审批驳回成功!" } errInfo.Code = 0 this.Data["json"] = &errInfo this.ServeJSON() } }() if Result == "1" && ProfessionalAudit == "" { panic("请选择审批人") } var lock sync.Mutex for i := 0; i < len(Ids); i++ { lock.Lock() //取出日常评审主表信息 conRev := contractReview.GetOilContractReviewService(utils.DBE) var contractReviewEntity contractReview.OilContractReview conRev.GetEntityById(Ids[i], &contractReviewEntity) svcActiviti := workflow.GetActivitiService(utils.DBE) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_DAILY_CONTRACT_EVALUATION ActiComplete.BusinessKey = contractReviewEntity.BusinessKey ActiComplete.UserId = this.User.Id //审批人员 ActiComplete.Result = Result //前台审批[同意、不同意] ActiComplete.UserNames = ProfessionalAudit ActiComplete.Remarks = AuditRemark ActiComplete.CallbackUrl = utils.Cfg.MustValue("workflow", "callbackHost") if len(Ids) > 1 { go func() { receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { log.Print("日常评价 工作流异常,业务ID:" + contractReviewEntity.BusinessKey + ",工作流信息:" + receiveVal) } else { if Result == "1" { cols := []string{ "Id", "Status", "ProfessionalAudit", } supplierCertId := strings.Split(contractReviewEntity.BusinessKey, "-")[0] contractReviewEntity.Status = suppliercert.PROF_AUDIT_STATUS //专业处室接收 contractReviewEntity.ProfessionalAudit, _ = strconv.Atoi(ProfessionalAudit) conRev.UpdateEntityByIdCols(supplierCertId, contractReviewEntity, cols) fmt.Println("业务处室分办协程!" + strconv.Itoa(i)) } } }() } else { receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { log.Print("日常评价 工作流异常,业务ID:" + contractReviewEntity.BusinessKey + ",工作流信息:" + receiveVal) } else { if Result == "1" { cols := []string{ "Id", "Status", "ProfessionalAudit", } supplierCertId := strings.Split(contractReviewEntity.BusinessKey, "-")[0] contractReviewEntity.Status = suppliercert.PROF_AUDIT_STATUS //专业处室接收 contractReviewEntity.ProfessionalAudit, _ = strconv.Atoi(ProfessionalAudit) conRev.UpdateEntityByIdCols(supplierCertId, contractReviewEntity, cols) fmt.Println("业务处室分办协程!" + strconv.Itoa(i)) } } } lock.Unlock() } } // @Title 业务处室提交评价审核 // @Description 业务处室提交评价审核 // @Success 200 {object} controllers.Request // @router /business-submit-review/:id [post] func (this *OilContractReviewController) BusinessSubmitEvaEntity() { Id := this.Ctx.Input.Param(":id") ProfessionalAudit := this.GetString("ProfessionalAudit") 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 ProfessionalAudit == "" { errInfo.Message = "请选择审批人" errInfo.Code = -1 this.Data["json"] = &errInfo this.ServeJSON() } //取出日常评审主表信息 conRev := contractReview.GetOilContractReviewService(utils.DBE) var contractReviewEntity contractReview.OilContractReview conRev.GetEntityById(Id, &contractReviewEntity) //取出合同表 contractSvc := contract.GetOilContractService(utils.DBE) var contractEntity contract.OilContract contractSvc.GetEntityById(contractReviewEntity.ContractId, &contractEntity) svcActiviti := workflow.GetActivitiService(utils.DBE) //启动工作流 businessKey := contractReviewEntity.BusinessKey processInstanceId := contractReviewEntity.WorkflowId // 如果被驳回,不再新启工作流 if processInstanceId == "" { //启动工作流 businessKey = Id + "-" + strconv.Itoa(contractReviewEntity.AuditIndex) processInstanceId = svcActiviti.StartProcess2(workflow.OIL_DAILY_CONTRACT_EVA_BY_BUSINESS, businessKey, this.User.Id, "1", contractEntity.ContractClass, contractEntity.SupplierName) if len(processInstanceId) <= 0 { panic("工作流启动失败!") } contractReviewEntity.AuditIndex += 1 } // 将启动和工作流,选择的初审和复审人员保存下来 cols := []string{ "Id", "WorkflowId", "BusinessKey", "ProcessKey", "CommitComId", "AuditIndex", "ProfessionalAudit", } contractReviewEntity.ProcessKey = workflow.OIL_DAILY_CONTRACT_EVA_BY_BUSINESS contractReviewEntity.BusinessKey = businessKey contractReviewEntity.WorkflowId = processInstanceId contractReviewEntity.CommitComId = strconv.Itoa(unitId) contractReviewEntity.ProfessionalAudit, _ = strconv.Atoi(ProfessionalAudit) conRev.UpdateEntityByIdCols(Id, contractReviewEntity, cols) var ActiComplete workflow.ActiCompleteVM ActiComplete.ProcessKey = workflow.OIL_DAILY_CONTRACT_EVA_BY_BUSINESS ActiComplete.BusinessKey = contractReviewEntity.BusinessKey ActiComplete.UserId = this.User.Id // 当前审批操作人员 ActiComplete.Result = "1" //业务处室分办提交给处室审核 ActiComplete.UserNames = ProfessionalAudit ActiComplete.Remarks = AuditRemark ActiComplete.CallbackUrl = utils.Cfg.MustValue("workflow", "callbackHost") receiveVal := svcActiviti.TaskComplete(ActiComplete) if receiveVal != "true" { panic("工作流异常,请联系管理员!" + receiveVal) } }