package oilsupplier import ( "dashoo.cn/backend/api/business/oilsupplier/badrecord" "dashoo.cn/backend/api/business/oilsupplier/supplierdataentry" "dashoo.cn/backend/api/business/workflow" . "dashoo.cn/backend/api/controllers" "dashoo.cn/business3/userRole" "dashoo.cn/utils" "encoding/json" "fmt" "reflect" "strconv" "strings" "time" ) type SupplierDataEntryController struct { BaseController } type RequestList struct { DocKey string DocAddress string DocName string DataEntryId int DocUrl string } type AddEntry struct { EntrustNo string ConUserId int Remark string ConUserBy string } type CopySheet struct { SheetNum int } type DataEntryCallback struct { Id string `json:"Id"` DocUrl string `json:"DocUrl"` } type PdfRequest struct { PdfUrl string `json:"pdfUrl"` Watermark string `json:"watermark"` } func StructToMapDemo(obj interface{}) map[string]interface{} { obj1 := reflect.TypeOf(obj) obj2 := reflect.ValueOf(obj) var data = make(map[string]interface{}) for i := 0; i < obj1.NumField(); i++ { data[obj1.Field(i).Name] = obj2.Field(i).Interface() } return data } // @Title 从数据录入数据导出到word文档 // @Description 数据存入word // @Success 200 {object} controllers.Request // @router /exportword/:tbid [post] func (this *SupplierDataEntryController) DocExport() { // 填物资类信息表首页信息 Id := this.Ctx.Input.Param(":tbid") certId := this.GetString("CertId") var Url string var fileName string var currencyType string svcActiviti := workflow.GetActivitiService(utils.DBE) var model1 supplierdataentry.SupplierDataEntry var model2 supplierdataentry.SupplierCertDataEntry svc := supplierdataentry.GetSupplierDataEntryService(utils.DBE) where1 := "1=1" where1 += " AND Id = '" + Id + "'" where2 := "Id = '" + certId + "'" svc.GetEntityByWhere(OilSupplierName, where1, &model1) svc.GetEntityByWhere(OilSupplierCertName, where2, &model2) businessKey := model2.BusinessKey processKey := model2.ProcessKey processInstanceId := model2.WorkflowId var historicTasks []workflow.ActiHistoricTask historicTasks = svcActiviti.GetHistoricMultiTasks(processKey, businessKey, processInstanceId) var tabledata3 []supplierdataentry.SupplierMajorEquipmentDataEntry var tabledata4 []supplierdataentry.SupplierThreeYearsDataEntryView var tabledata5 []supplierdataentry.SupplierPatentDataEntryView var tabledata6 []supplierdataentry.SupplierWinningDataEntryView var tabledata7 []supplierdataentry.SupplierCertSubEntry SupplierCertId := strconv.Itoa(model2.Id) where3 := "SupplierCertId = " + SupplierCertId + " LIMIT 5" svc.GetSelect(OilEnterpriseMajorEquipmentName, where3, &tabledata3) where4 := "SupplierCertId = " + SupplierCertId + " LIMIT 5" svc.GetSelect(OilThreeYearsPerformanceName, where4, &tabledata4) where5 := "SupplierCertId = " + SupplierCertId + " LIMIT 7" svc.GetSelect(OilPatentStatisticalName, where5, &tabledata5) where9 := "SupplierCertId = " + SupplierCertId + " LIMIT 9" svc.GetSelect(OilWinningProjectName, where9, &tabledata6) where := "SupplierCertId = " + SupplierCertId+" and Type in ('1','3') and CertSubStatus='1'" svc.GetEntitysByOrderbyWhere(OilSupplierCertSubName, where, "1", &tabledata7) datamap := StructToMapDemo(model1.OilSupplier) if model2.SupplierTypeCode == "01" { //Url = "http://weed1.labsop.cn:9390/1,248318341f7c" Url = utils.Cfg.MustValue("workflow", "goodsModuleHost") fileName = "物资类供方准入评审表.docx" } else if model2.SupplierTypeCode == "02" { //Url = "http://weed1.labsop.cn:9390/5,2479ad04d28b" Url = utils.Cfg.MustValue("workflow", "basisModuleHost") fileName = "基建类供方准入评审表.docx" datamap["TJInNotify"] = model1.TJInNotify } else { //Url = "http://weed1.labsop.cn:9390/2,247af827d5ac" Url = utils.Cfg.MustValue("workflow", "techModuleHost") fileName = "服务类供方准入评审表.docx" } //model1 datamap["SetupTime"] = model1.SetupTime.Format("2006年01月02日") if model1.OperType != "" { if model1.OperType == "1" || model1.OperType == "制造商"{ datamap["OperType"] = "☑制造商 □代理商 □贸易商" }else if model1.OperType == "2" || model1.OperType == "代理商"{ datamap["OperType"] = "□制造商 ☑代理商 □贸易商" }else if model1.OperType == "3" || model1.OperType == "代理商"{ datamap["OperType"] = "□制造商 □代理商 ☑贸易商" }else { datamap["OperType"] = "□制造商 □代理商 □贸易商" } } if model1.SpecTypeCode != "" { if model1.SpecTypeCode == "1"{ datamap["SpecTypeCode"] = "☑一般外部 □多元企业" }else if model1.SpecTypeCode == "2"{ datamap["SpecTypeCode"] = "□一般外部 ☑多元企业" }else { datamap["SpecTypeCode"] = "□一般外部 □多元企业" } } if model1.Grade == "1"{ datamap["Grade"] = "一级" }else if model1.SpecTypeCode == "2"{ datamap["Grade"] = "二级" } //datamap["QualifCert"] = model1.QualifCert //datamap["QualifCertLevel"] = model1.QualifCertLevel //datamap["SpecIndustryCert"] = model1.SpecIndustryCert //datamap["MaunLicense"] = model1.MaunLicense //datamap["HseTraining"] = model1.HseTraining //datamap["Fax"] = model1.Fax //datamap["CompanyTel"] = model1.CompanyTel //datamap["SupplierName"] = model1.SupplierName //datamap["SpecTypeCode"] = model1.SpecTypeName //datamap["Country"] = model1.Country //datamap["MaunAgent"] = model1.MaunAgent //datamap["SupplierCertificate"] = model1.SupplierCertificate //datamap["MgrUnit"] = model1.MgrUnit //datamap["Grade"] = model1.Grade //datamap["CommercialNo"] = model1.CommercialNo //datamap["CountryTaxNo"] = model1.CountryTaxNo //datamap["OrganCode"] = model1.OrganCode //datamap["Address"] = model1.Address //datamap["ZipCode"] = model1.ZipCode //datamap["LinkAddress"] = model1.LinkAddress //datamap["LinkZipCode"] = model1.LinkZipCode //datamap["QualitySystemCert"] = model1.QualitySystemCert //datamap["ProductQualityCert"] = model1.ProductQualityCert //datamap["MaunLicense"] = model1.MaunLicense //datamap["LegalPerson"] = model1.LegalPerson //datamap["CompanyType"] = model1.CompanyType //datamap["ContactName"] = model1.ContactName if model1.Currency == "CNY" || model1.Currency == "人民币元"{ currencyType = "人民币" }else if model1.Currency == "USD" { currencyType ="美元" }else if model1.Currency == "EUR" { currencyType = "欧元" }else if model1.Currency=="JPY"{ currencyType = "日元" }else if model1.Currency == ""{ currencyType="万元" } datamap["RegCapital"] = strconv.FormatFloat(model1.RegCapital,'f',0,64)+"万元"+currencyType //datamap["DepositBank"] = model1.DepositBank //datamap["BankAccount"] = model1.BankAccount //datamap["Mobile"] = model1.Mobile //datamap["EMail"] = model1.EMail //datamap["BankCreditRating"] = model1.BankCreditRating //datamap["BusinessScope"] = model1.BusinessScope //datamap["Telphone"] = model1.Telphone //model2 datamap["WorkerTotal"] = model2.WorkerTotal datamap["ContractNum"] = model2.ContractNum datamap["UniversityNum"] = model2.UniversityNum datamap["TechnicalNum"] = model2.TechnicalNum datamap["AboveProfNum"] = model2.AboveProfNum datamap["MiddleProfNum"] = model2.MiddleProfNum datamap["NationalRegNum"] = model2.NationalRegNum datamap["NationalCertTotal"] = model2.NationalCertTotal datamap["DesignerTotal"] = model2.DesignerTotal datamap["SkillerTotal"] = model2.SkillerTotal datamap["AccessCardNo"] = model2.AccessCardNo if len(tabledata7) != 0 { var Name string Name = tabledata7[0].Code Name = Name + " " + tabledata7[0].Name var i int for i = 1; i < len(tabledata7) && i < 25; i++ { Name += ";" Name += tabledata7[i].Code Name = Name + " " + tabledata7[i].Name } if i == 25 { Name += "(更多准入内容详见《市场管理信息系统》)" } datamap["Name"] = Name } else { datamap["Name"] = "" } for i,item := range tabledata3 { datamap["MajorEquipments" + strconv.Itoa(i + 1)] = item.MainEquipment datamap["Specifications" + strconv.Itoa(i + 1)] = item.Specifications datamap["Number" + strconv.Itoa(i + 1)] = item.Number datamap["Remark" + strconv.Itoa(i + 1)] = item.Remark } for i,item := range tabledata4 { datamap["ProjectName" + strconv.Itoa(i + 1)] = item.ProjectName datamap["BearContent" + strconv.Itoa(i + 1)] = item.BearContent datamap["TimeStr" + strconv.Itoa(i + 1)] = item.StartTime.Format("2006-01-02") + "--" + item.StopTime.Format("2006-01-02") datamap["Tudge" + strconv.Itoa(i + 1)] = item.Tudge } for i,item := range tabledata5 { datamap["Patent" + strconv.Itoa(i + 1)] = item.Name datamap["Pcontent" + strconv.Itoa(i + 1)] = item.Content datamap["ApprovalAuthority" + strconv.Itoa(i + 1)] = item.ApprovalAuthority datamap["ApprovalDateStr" + strconv.Itoa(i + 1)] = item.ApprovalDate.Format("2006-01-02") } for i,item := range tabledata6 { datamap["AwardName" + strconv.Itoa(i + 1)] = item.AwardName datamap["WinningTimeStr" + strconv.Itoa(i + 1)] = item.WinningTime.Format("2006-01-02") datamap["Authorities" + strconv.Itoa(i + 1)] = item.Authorities datamap["Aremark" + strconv.Itoa(i + 1)] = item.Remark } //审批意见 datamap["FName"] = "" // 初审 datamap["FOpinion"] = "" datamap["YDate"] = " 年 月 日" // 初审 datamap["SName"] = "" datamap["SDate"] = " 年 月 日" // 复审 datamap["OName"] = "" datamap["ODate"] = " 年 月 日" // 专业处室 datamap["SOpinion"] = "" datamap["OfficeRemarks"] = "" datamap["ZDate"] = " 年 月 日" // 集中评审 datamap["ZOPinion"] = "" for i := 0; i < len(historicTasks); i++ { fmt.Println(historicTasks[i].EndTime) if historicTasks[i].TaskName == "业务处室专业审批" { var user userRole.Base_User svc.GetEntityById(historicTasks[i].Assignee, &user) datamap["OfficeRemarks"] = historicTasks[i].Remarks datamap["OName"] = user.Realname datamap["ODate"] = time.Unix(historicTasks[i].EndTime / 1e3, 0).Format("2006年01月02日") } else if historicTasks[i].TaskName == "二级单位初审" { var user userRole.Base_User svc.GetEntityById(historicTasks[i].Assignee, &user) datamap["FOpinion"] = historicTasks[i].Remarks datamap["FName"] = user.Realname datamap["YDate"] = time.Unix(historicTasks[i].EndTime / 1e3,0).Format("2006年01月02日") } else if historicTasks[i].TaskName == "二级单位复审" { var user userRole.Base_User svc.GetEntityById(historicTasks[i].Assignee, &user) datamap["SOpinion"] = historicTasks[i].Remarks datamap["SName"] = user.Realname datamap["SDate"] = time.Unix(historicTasks[i].EndTime / 1e3,0).Format("2006年01月02日") } else if historicTasks[i].TaskName == "集中评审" { var user userRole.Base_User svc.GetEntityById(historicTasks[i].Assignee, &user) datamap["ZOPinion"] = historicTasks[i].Remarks datamap["ZDate"] = time.Unix(historicTasks[i].EndTime / 1e3,0).Format("2006年01月02日") } } //var interfaceSlice3 = make([]interface{}, len(tabledata3)) //for i, d := range tabledata3 { // interfaceSlice3[i] = d //} //datamap["MajorEquipments"] = workflow.TableDetailData{ // DataList: interfaceSlice3, // StartRow: 28, // NeedDelRow: 5, // ReverseRow: 0, // Cols: []string{"MajorEquipment", "Specifications", "Number", "Remark"}, // Merge: []string{"1,3"}, // ColsNum: 18, //} // ////起止时间如何全部显示 //var interfaceSlice4 = make([]interface{}, len(tabledata4)) //for i, d := range tabledata4 { // d.StartTimeStr = d.StopTime.Format("2006-01-02") // interfaceSlice4[i] = d //} //datamap["ThreeYears"] = workflow.TableDetailData{ // DataList: interfaceSlice4, // StartRow: 35, // NeedDelRow: 5, // ReverseRow: 0, // Cols: []string{"ProjectName", "BearContent", "OwnerUnit", "StartTimeStr", "StartTimeStr", "Tudge"}, // Merge: []string{}, // ColsNum: 5, //} // //var interfaceSlice5 = make([]interface{}, len(tabledata5)) //for i, d := range tabledata5 { // d.ApprovalDateStr = d.ApprovalDate.Format("2006-01-02") // interfaceSlice5[i] = d //} //datamap["Patent"] = workflow.TableDetailData{ // DataList: interfaceSlice5, // StartRow: 42, // NeedDelRow: 7, // ReverseRow: 0, // Cols: []string{"Name", "Content", "ApprovalAuthority", "ApprovalDateStr"}, // Merge: []string{}, // ColsNum: 4, //} // //var interfaceSlice6 = make([]interface{}, len(tabledata6)) //for i, d := range tabledata6 { // d.WinningTimeStr = d.WinningTime.Format("2006-01-02") // interfaceSlice6[i] = d //} //datamap["Winning"] = workflow.TableDetailData{ // DataList: interfaceSlice6, // StartRow: 51, // NeedDelRow: 9, // ReverseRow: 0, // Cols: []string{"AwardName", "WinningTimeStr", "Authorities", "Remark"}, // Merge: []string{}, // ColsNum: 4, //} //datamap["TableComment"] = []string{"MajorEquipments", "ThreeYears", "Patent", "Winning"} //retDocUrl := svcActiviti.FillWordTemplate(datamap, Url, fileName) retDocUrl := svcActiviti.FillWordWatermarkTemplate(datamap, Url, fileName, model1.SupplierName) var datainfo ErrorDataInfo datainfo.Code = 0 datainfo.Item = retDocUrl datainfo.Message = "打印成功" this.Data["json"] = &datainfo this.ServeJSON() } // @Title 导出数据到word,作为导出pdf的中间步骤 // @Description 数据存入word // @Success 200 {object} controllers.Request // @router /exportpdf/:tbid/:typecode [post] func (this *SupplierDataEntryController) PdfExport() { Id := this.Ctx.Input.Param(":tbid") SupplierTypeCode := this.Ctx.Input.Param(":typecode") var Url string var fileName string var model1 supplierdataentry.SupplierDataEntry var model2 supplierdataentry.SupplierCertDataEntry svc := supplierdataentry.GetSupplierDataEntryService(utils.DBE) where1 := "1=1" where1 += " AND Id = '" + Id + "'" where2 := "SupplierId = '" + Id + "' and SupplierTypecode='"+ SupplierTypeCode +"'" svc.GetEntityByWhere(OilSupplierName, where1, &model1) svc.GetEntityByWhere(OilSupplierCertName, where2, &model2) var tabledata []supplierdataentry.SupplierCertSubEntry where3:="SupplierId = '" + Id + "' and SupplierTypecode='"+ SupplierTypeCode +"' and CertSubStatus='1' and Type in ('1','3')"//准入状态的准入项 svc.GetEntitysByOrderbyWhere(OilSupplierCertSubName, where3, "1", &tabledata) var tabledata2 []supplierdataentry.SupplierCertSubEntry where4:="SupplierId = '" + Id + "' and SupplierTypecode='"+ SupplierTypeCode +"' and CertSubStatus='2' and Type in ('1','3')"//暂停状态的准入项 svc.GetEntitysByOrderbyWhere(OilSupplierCertSubName, where4, "1", &tabledata2) datamap := StructToMapDemo(model1.OilSupplier) if model2.SupplierTypeCode == "01" { Url = utils.Cfg.MustValue("workflow", "goodsPdfHost") fileName = "物资类准入范围.docx" } else if model2.SupplierTypeCode == "02" { Url = utils.Cfg.MustValue("workflow", "basisPdfHost") fileName = "基建类准入范围.docx" datamap["TJInNotify"] = model1.TJInNotify } else { Url = utils.Cfg.MustValue("workflow", "techPdfHost") fileName = "服务类准入范围.docx" } //model1 datamap["SetupTime"] = model1.SetupTime.Format("2006年01月02日") datamap["QualifCert"] = model1.QualifCert datamap["QualifCertLevel"] = model1.QualifCertLevel datamap["SpecIndustryCert"] = model1.SpecIndustryCert datamap["MaunLicense"] = model1.MaunLicense if model1.HseTraining == "1" { datamap["HseTraining"] = "是" } else { datamap["HseTraining"] = "否" } if model1.OperType != "" { if model1.OperType == "1" || model1.OperType == "制造商"{ datamap["OperType"] = "√制造商 □代理商 □贸易商" }else if model1.OperType == "2" || model1.OperType == "代理商"{ datamap["OperType"] = "□制造商 √代理商 □贸易商" }else if model1.OperType == "3" || model1.OperType == "代理商"{ datamap["OperType"] = "□制造商 □代理商 √贸易商" }else { datamap["OperType"] = "□制造商 □代理商 □贸易商" } } if model1.SpecTypeCode != "" { if model1.SpecTypeCode == "1"{ datamap["SpecTypeCode"] = "√一般外部 □多元企业" }else if model1.SpecTypeCode == "2"{ datamap["SpecTypeCode"] = "□一般外部 √多元企业" }else { datamap["SpecTypeCode"] = "□一般外部 □多元企业" } } if model1.Grade == "1"{ datamap["Grade"] = "一级" }else if model1.SpecTypeCode == "2"{ datamap["Grade"] = "二级" } datamap["Fax"] = model1.Fax datamap["CompanyTel"] = model1.CompanyTel datamap["SupplierName"] = model1.SupplierName datamap["Country"] = model1.Country datamap["MaunAgent"] = model1.MaunAgent datamap["SupplierCertificate"] = model1.SupplierCertificate datamap["MgrUnit"] = model1.MgrUnit datamap["CommercialNo"] = model1.CommercialNo datamap["CountryTaxNo"] = model1.CountryTaxNo datamap["OrganCode"] = model1.OrganCode datamap["Address"] = model1.Address datamap["ZipCode"] = model1.ZipCode datamap["LinkAddress"] = model1.LinkAddress datamap["LinkZipCode"] = model1.LinkZipCode datamap["QualitySystemCert"] = model1.QualitySystemCert datamap["ProductQualityCert"] = model1.ProductQualityCert datamap["MaunLicense"] = model1.MaunLicense datamap["LegalPerson"] = model1.LegalPerson datamap["CompanyType"] = model1.CompanyType datamap["ContactName"] = model1.ContactName datamap["RegCapital"] = strconv.FormatFloat(model1.RegCapital,'f',2,64)+"万元"+model1.Currency datamap["DepositBank"] = model1.DepositBank datamap["BankAccount"] = model1.BankAccount datamap["Mobile"] = model1.Mobile datamap["EMail"] = model1.EMail datamap["BankCreditRating"] = model1.BankCreditRating datamap["BusinessScope"] = model1.BusinessScope datamap["Telphone"] = model1.Telphone datamap["AccessCardNo"] = model2.AccessCardNo datamap["PrintYear"] = time.Now().Year() datamap["PrintMonth"] = time.Now().Month() datamap["PrintDay"] = time.Now().Day() //获取准入项不良记录 zhunruStr := "" if len(tabledata2) != 0{ zhunruStr = "准入:" var badRecord BadRecord.BadRecord svc.GetEntity(&badRecord,"CompanyCode='"+Id+"'") //拼接已暂停准入范围编码名称 var Name string Name = "\n已暂停: " + tabledata2[0].Code Name = Name + " " + tabledata2[0].Name var i int for i = 1; i < len(tabledata2); i++ { Name += ";" Name += tabledata2[i].Code Name = Name + " " + tabledata2[i].Name } datamap["Name"]=Name + " \n暂停原因:"+badRecord.Certrecord+"" }else{ datamap["Name"] = "" } if len(tabledata) != 0 { var Name string Name = "\n"+ zhunruStr + strings.TrimSpace(tabledata[0].Code) Name = Name + " " + strings.TrimSpace(tabledata[0].Name) var i int for i = 1; i < len(tabledata); i++ { Name += ";" Name += strings.TrimSpace(tabledata[i].Code) Name = Name + " " + strings.TrimSpace(tabledata[i].Name) } //if i == 100 { // Name += "(准入范围未完全显示,请到系统查看详情)" //} fmt.Println(Name) datamap["Name"] =datamap["Name"].(string) + Name } else { datamap["Name"] =datamap["Name"].(string) } /*var interfaceSlice2 = make([]interface{}, len(tabledata)) for i, d := range tabledata { interfaceSlice2[i] = d } datamap["CertSub"] = workflow.TableDetailData{ DataList: interfaceSlice2, StartRow: 2, NeedDelRow: 1, ReverseRow: 10, Cols: []string{"Code", "Name"}, Merge: []string{}, ColsNum: 2, } datamap["TableComment"] = []string{"CertSub"}*/ svcActiviti := workflow.GetActivitiService(utils.DBE) retDocUrl := svcActiviti.FillWordTemplate(datamap, Url, fileName) var datainfo ErrorDataInfo datainfo.Code = 0 datainfo.Item = retDocUrl datainfo.Message = "准备导出" this.Data["json"] = &datainfo this.ServeJSON() } // @Title post // @Description word to pdf // @Success 200 {string} pdfurl // @router /word-to-pdf [post] func (this *SupplierDataEntryController) WordToPdf() { var pdfurl = this.GetString("pdfurl") svcActiviti := workflow.GetActivitiService(utils.DBE) pdfUrl := svcActiviti.WordToPdf(pdfurl) this.Data["json"] = pdfUrl this.ServeJSON() } // @Title post // @Description word to pdf // @Success 200 {string} pdfurl // @router /word-to-pdf-watermark [post] func (this *SupplierDataEntryController) WordToPdfWithWatermark() { var pdfRequest PdfRequest var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &pdfRequest) svcActiviti := workflow.GetActivitiService(utils.DBE) pdfUrl := svcActiviti.WordToPdfWithWatermark(pdfRequest.Watermark, pdfRequest.PdfUrl) this.Data["json"] = pdfUrl this.ServeJSON() }