正在显示
7 个修改的文件
包含
119 行增加
和
12 行删除
| @@ -5,9 +5,11 @@ import ( | @@ -5,9 +5,11 @@ import ( | ||
| 5 | "fmt" | 5 | "fmt" |
| 6 | "oppmg/common/log" | 6 | "oppmg/common/log" |
| 7 | "oppmg/protocol" | 7 | "oppmg/protocol" |
| 8 | + "oppmg/utils/exceltool" | ||
| 8 | "strconv" | 9 | "strconv" |
| 9 | 10 | ||
| 10 | "github.com/astaxie/beego" | 11 | "github.com/astaxie/beego" |
| 12 | + "github.com/astaxie/beego/context" | ||
| 11 | "github.com/astaxie/beego/validation" | 13 | "github.com/astaxie/beego/validation" |
| 12 | ) | 14 | ) |
| 13 | 15 | ||
| @@ -85,3 +87,16 @@ func (this *BaseController) Valid(obj interface{}) (result bool, msg *protocol.R | @@ -85,3 +87,16 @@ func (this *BaseController) Valid(obj interface{}) (result bool, msg *protocol.R | ||
| 85 | 87 | ||
| 86 | return | 88 | return |
| 87 | } | 89 | } |
| 90 | + | ||
| 91 | +func (this *BaseController) ResponseExcelByFile(ctx *context.Context, excelMaker *exceltool.ExcelMaker) error { | ||
| 92 | + ctx.Output.Header("Content-Disposition", "attachment; filename="+excelMaker.FileName) | ||
| 93 | + ctx.Output.Header("Content-Description", "File Transfer") | ||
| 94 | + ctx.Output.Header("Content-Type", "application/octet-stream") | ||
| 95 | + ctx.Output.Header("Content-Transfer-Encoding", "binary") | ||
| 96 | + ctx.Output.Header("Expires", "0") | ||
| 97 | + ctx.Output.Header("Cache-Control", "must-revalidate") | ||
| 98 | + ctx.Output.Header("Pragma", "public") | ||
| 99 | + //跳过保存文件,直接写入ctx.ResponseWriter | ||
| 100 | + excelMaker.Xlsx.Write(ctx.ResponseWriter) | ||
| 101 | + return nil | ||
| 102 | +} |
| @@ -175,3 +175,39 @@ func (this *BulletinController) BulletinFeedbacks() { | @@ -175,3 +175,39 @@ func (this *BulletinController) BulletinFeedbacks() { | ||
| 175 | rsp, err := bulletin.BulletinFeedbacks(companyId, request) | 175 | rsp, err := bulletin.BulletinFeedbacks(companyId, request) |
| 176 | msg = protocol.NewPageDataResponse(rsp, err) | 176 | msg = protocol.NewPageDataResponse(rsp, err) |
| 177 | } | 177 | } |
| 178 | + | ||
| 179 | +//ExportFeedBacks | ||
| 180 | +//@router /exportFeedBacks [post] | ||
| 181 | +func (this *BulletinController) ExportFeedBacks() { | ||
| 182 | + var msg *protocol.ResponseMessage | ||
| 183 | + defer func() { | ||
| 184 | + this.ResposeJson(msg) | ||
| 185 | + }() | ||
| 186 | + var request *protocol.ExportFeedBacksRequest | ||
| 187 | + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { | ||
| 188 | + log.Error("json 解析失败", err) | ||
| 189 | + msg = protocol.BadRequestParam("1") | ||
| 190 | + return | ||
| 191 | + } | ||
| 192 | + if b, m := this.Valid(request); !b { | ||
| 193 | + msg = m | ||
| 194 | + return | ||
| 195 | + } | ||
| 196 | + companyId := this.GetCompanyId() | ||
| 197 | + if companyId <= 0 { | ||
| 198 | + msg = protocol.BadRequestParam("1") | ||
| 199 | + return | ||
| 200 | + } | ||
| 201 | + excel, err := bulletin.ExportFeedBacks(companyId, request) | ||
| 202 | + if err != nil { | ||
| 203 | + log.Error(err.Error()) | ||
| 204 | + msg = protocol.BadRequestParam("1") | ||
| 205 | + return | ||
| 206 | + } | ||
| 207 | + if err = this.ResponseExcelByFile(this.Ctx, excel); err != nil { | ||
| 208 | + log.Error(err.Error()) | ||
| 209 | + msg = protocol.BadRequestParam("1") | ||
| 210 | + return | ||
| 211 | + } | ||
| 212 | + msg = protocol.NewReturnResponse(nil, err) | ||
| 213 | +} |
| @@ -86,17 +86,16 @@ select answer,update_at,uid from bulletin_question_answer where bulletin_id =? | @@ -86,17 +86,16 @@ select answer,update_at,uid from bulletin_question_answer where bulletin_id =? | ||
| 86 | sqlCount += where | 86 | sqlCount += where |
| 87 | 87 | ||
| 88 | sql += where | 88 | sql += where |
| 89 | - sql += ` limit ?,?` | 89 | + if err = utils.ExecuteQueryOne(&total, sqlCount, id); err != nil { |
| 90 | + return | ||
| 91 | + } | ||
| 92 | + if page > 0 { | ||
| 93 | + sql += fmt.Sprintf(` limit %v,%v`, (page-1)*pageSize, pageSize) | ||
| 94 | + } | ||
| 90 | if v != nil { | 95 | if v != nil { |
| 91 | - if err = utils.ExecuteQueryOne(&total, sqlCount, id); err != nil { | 96 | + if err = utils.ExecuteQueryAll(v, sql, id); err != nil { |
| 92 | return | 97 | return |
| 93 | } | 98 | } |
| 94 | } | 99 | } |
| 95 | - if page == 0 { | ||
| 96 | - page = 1 | ||
| 97 | - } | ||
| 98 | - if err = utils.ExecuteQueryAll(v, sql, id, (page-1)*pageSize, pageSize); err != nil { | ||
| 99 | - return | ||
| 100 | - } | ||
| 101 | return | 100 | return |
| 102 | } | 101 | } |
| @@ -128,3 +128,10 @@ type Answer struct { | @@ -128,3 +128,10 @@ type Answer struct { | ||
| 128 | VoteResults []int `json:"voteResults"` | 128 | VoteResults []int `json:"voteResults"` |
| 129 | EditContent string `json:"editContent"` | 129 | EditContent string `json:"editContent"` |
| 130 | } | 130 | } |
| 131 | + | ||
| 132 | +/*ExportFeedBacks */ | ||
| 133 | +type ExportFeedBacksRequest struct { | ||
| 134 | + Id int `json:"id"` //公告编号 | ||
| 135 | +} | ||
| 136 | +type ExportFeedBacksResponse struct { | ||
| 137 | +} |
| @@ -53,6 +53,7 @@ func init() { | @@ -53,6 +53,7 @@ func init() { | ||
| 53 | beego.NSRouter("/update", &controllers.BulletinController{}, "post:UpdateBulletin"), | 53 | beego.NSRouter("/update", &controllers.BulletinController{}, "post:UpdateBulletin"), |
| 54 | beego.NSRouter("/operate", &controllers.BulletinController{}, "post:OperateBulletin"), | 54 | beego.NSRouter("/operate", &controllers.BulletinController{}, "post:OperateBulletin"), |
| 55 | beego.NSRouter("/feedbacks", &controllers.BulletinController{}, "post:BulletinFeedbacks"), | 55 | beego.NSRouter("/feedbacks", &controllers.BulletinController{}, "post:BulletinFeedbacks"), |
| 56 | + beego.NSRouter("/exportFeedBacks", &controllers.BulletinController{}, "post:ExportFeedBacks"), | ||
| 56 | ), | 57 | ), |
| 57 | beego.NSNamespace("/common", | 58 | beego.NSNamespace("/common", |
| 58 | beego.NSRouter("/department", &controllers.CommonController{}, "post:SelectorDepartment"), | 59 | beego.NSRouter("/department", &controllers.CommonController{}, "post:SelectorDepartment"), |
| @@ -9,6 +9,7 @@ import ( | @@ -9,6 +9,7 @@ import ( | ||
| 9 | "oppmg/protocol" | 9 | "oppmg/protocol" |
| 10 | "oppmg/services/agg" | 10 | "oppmg/services/agg" |
| 11 | "oppmg/utils" | 11 | "oppmg/utils" |
| 12 | + "oppmg/utils/exceltool" | ||
| 12 | "strconv" | 13 | "strconv" |
| 13 | "strings" | 14 | "strings" |
| 14 | "time" | 15 | "time" |
| @@ -452,3 +453,37 @@ func BulletinFeedbacks(companyId int64, request *protocol.BulletinFeedbacksReque | @@ -452,3 +453,37 @@ func BulletinFeedbacks(companyId int64, request *protocol.BulletinFeedbacksReque | ||
| 452 | } | 453 | } |
| 453 | return | 454 | return |
| 454 | } | 455 | } |
| 456 | + | ||
| 457 | +//导出反馈详情 | ||
| 458 | +func ExportFeedBacks(companyId int64, request *protocol.ExportFeedBacksRequest) (excel *exceltool.ExcelMaker, err error) { | ||
| 459 | + var ( | ||
| 460 | + feedbackRsp *protocol.BulletinFeedbacksResponse | ||
| 461 | + sourceData []map[string]string | ||
| 462 | + ) | ||
| 463 | + if feedbackRsp, err = BulletinFeedbacks(companyId, &protocol.BulletinFeedbacksRequest{Id: request.Id}); err != nil { | ||
| 464 | + //if err == orm2.ErrNoRows { | ||
| 465 | + // err = nil | ||
| 466 | + //} | ||
| 467 | + //无数据 | ||
| 468 | + return | ||
| 469 | + } | ||
| 470 | + excel = exceltool.NewExcelMaker() | ||
| 471 | + headTitle := [][]string{ | ||
| 472 | + []string{"time", "时间"}, | ||
| 473 | + []string{"name", "姓名"}, | ||
| 474 | + []string{"content", "选项"}, | ||
| 475 | + } | ||
| 476 | + for i := range feedbackRsp.List { | ||
| 477 | + item := feedbackRsp.List[i] | ||
| 478 | + row := make(map[string]string) | ||
| 479 | + row["time"] = time.Unix(item.Time, 0).Format("2006-01-02 15:04:05") | ||
| 480 | + row["name"] = item.Name | ||
| 481 | + row["content"] = item.Content | ||
| 482 | + sourceData = append(sourceData, row) | ||
| 483 | + } | ||
| 484 | + if err = excel.MakeListExcel(sourceData, headTitle); err != nil { | ||
| 485 | + log.Error(err.Error()) | ||
| 486 | + return | ||
| 487 | + } | ||
| 488 | + return | ||
| 489 | +} |
| @@ -39,10 +39,11 @@ func (e *ExcelMaker) MakeListExcel(sourData []map[string]string, xlsxHeader [][] | @@ -39,10 +39,11 @@ func (e *ExcelMaker) MakeListExcel(sourData []map[string]string, xlsxHeader [][] | ||
| 39 | } | 39 | } |
| 40 | headEn = append(headEn, xlsxHeader[key][0]) | 40 | headEn = append(headEn, xlsxHeader[key][0]) |
| 41 | headCn = append(headCn, xlsxHeader[key][1]) | 41 | headCn = append(headCn, xlsxHeader[key][1]) |
| 42 | - alpha, err := excelize.ColumnNumberToName(key) | ||
| 43 | - if err != nil { | ||
| 44 | - return err | ||
| 45 | - } | 42 | + //alpha, err := excelize.ColumnNumberToName(key) |
| 43 | + //if err != nil { | ||
| 44 | + // return err | ||
| 45 | + //} | ||
| 46 | + alpha := ToAlphaString(key) | ||
| 46 | alphaSlice = append(alphaSlice, alpha) | 47 | alphaSlice = append(alphaSlice, alpha) |
| 47 | } | 48 | } |
| 48 | 49 | ||
| @@ -119,3 +120,16 @@ func GetRandomString(lenght int) string { | @@ -119,3 +120,16 @@ func GetRandomString(lenght int) string { | ||
| 119 | } | 120 | } |
| 120 | return string(result) | 121 | return string(result) |
| 121 | } | 122 | } |
| 123 | + | ||
| 124 | +func ToAlphaString(value int) string { | ||
| 125 | + if value < 0 { | ||
| 126 | + return "" | ||
| 127 | + } | ||
| 128 | + var ans string | ||
| 129 | + i := value + 1 | ||
| 130 | + for i > 0 { | ||
| 131 | + ans = string((i-1)%26+65) + ans | ||
| 132 | + i = (i - 1) / 26 | ||
| 133 | + } | ||
| 134 | + return ans | ||
| 135 | +} |
-
请 注册 或 登录 后发表评论