diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/admin/companyinout.go b/admin/companyinout.go index b858576..c8e4359 100644 --- a/admin/companyinout.go +++ b/admin/companyinout.go @@ -13,7 +13,101 @@ import ( "unicode" ) +func convertToTitle(columnNumber int) string { + var res []byte + for columnNumber > 0 { + a := columnNumber % 26 + if a == 0 { + a = 26 + } + res = append(res, 'A'+byte(a-1)) + columnNumber = (columnNumber - a) / 26 + } + // 上面输出的res是反着的,前后交换 + for i, n := 0, len(res); i < n/2; i++ { + res[i], res[n-1-i] = res[n-1-i], res[i] + } + return string(res) +} + var CompanyInOutCtr = Ctr{ + //下载政企超链接里面填报的数据 + "downloadQuestion": func(that *Context) { + orgId := ObjToInt(that.Req.FormValue("org_id")) + if orgId == 0 { + that.Display(3, "参数错误") + return + } + + filePath := "temp/downloadQuestion" + ObjToStr(orgId) + ".xlsx" + f, e := excelize.OpenFile(that.Config.GetString("tpt") + "/" + filePath) + // 设置单元格的值 + questions := that.Db.Query("SELECT user.name AS user_name,user.phone,company.name AS company_name,question_company.name,question_company.question_data,question_company.status,question_company.modify_time FROM question_company INNER JOIN `user` ON question_company.`user_id`=`user`.id INNER JOIN `company` ON question_company.`company_id`=`company`.id WHERE question_company.org_id=?", orgId) + if e != nil { + f = excelize.NewFile() + } + // 创建一个工作表 + f.NewSheet("企业填报") + + f.DeleteSheet("Sheet1") + + //cs := append(NewCompanys{}, companys...) + f.SetCellValue("企业填报", convertToTitle(1)+"1", "调查名") + f.SetCellValue("企业填报", convertToTitle(2)+"1", "企业名") + f.SetCellValue("企业填报", convertToTitle(3)+"1", "姓名") + f.SetCellValue("企业填报", convertToTitle(4)+"1", "手机号") + f.SetCellValue("企业填报", convertToTitle(5)+"1", "状态") + f.SetCellValue("企业填报", convertToTitle(6)+"1", "修改时间") + for k, question := range questions { + //企业基础信息 + f.SetCellValue("企业填报", convertToTitle(1)+ObjToStr(k+5), question.GetString("name")) + f.SetCellValue("企业填报", convertToTitle(2)+ObjToStr(k+5), question.GetString("company_name")) + f.SetCellValue("企业填报", convertToTitle(3)+ObjToStr(k+5), question.GetString("user_name")) + f.SetCellValue("企业填报", convertToTitle(4)+ObjToStr(k+5), question.GetString("phone")) + f.SetCellValue("企业填报", convertToTitle(5)+ObjToStr(k+5), question.GetString("status")) + f.SetCellValue("企业填报", convertToTitle(6)+ObjToStr(k+5), time.Unix(question.GetCeilInt64("modify_time"), 0).Format("2006-01-02 15:04")) + //企业问题信息基础信息 + questionData := question.GetSlice("question_data") + for k1, _ := range questionData { + v1 := questionData.GetMap(k1) + if k == 0 { + f.SetCellValue("企业填报", convertToTitle(k1+7)+"1", v1.GetString("label")) + f.SetCellValue("企业填报", convertToTitle(k1+7)+"2", v1.GetString("unit")) + f.SetCellValue("企业填报", convertToTitle(k1+7)+"3", v1.GetString("remarks")) + f.SetCellValue("企业填报", convertToTitle(k1+7)+"4", v1.GetString("type")) + } + value := v1.GetString("value") + extend := v1.GetSlice("extend") + if extend != nil && len(extend) > 0 { + for k2, _ := range extend { + v2 := extend.GetMap(k2) + value = value + ";" + v2.GetString("value") + } + } + + f.SetCellValue("企业填报", convertToTitle(k1+7)+ObjToStr(k+5), value) + + } + + //break + + } + + os.MkdirAll(that.Config.GetString("tpt")+"/temp/", os.ModeDir) + // 根据指定路径保存文件 + if err := f.SaveAs(that.Config.GetString("tpt") + "/" + filePath); err != nil { + fmt.Println(err) + that.Display(4, "输出异常") + return + } + + //} + f.Save() + that.Resp.Header().Set("Location", "/"+filePath) + that.Resp.WriteHeader(307) //关键在这里! + that.Display(0, filePath) + + }, "upload": func(this *Context) { orgId := ObjToInt(this.Req.FormValue("org_id"))