|
@@ -7,12 +7,15 @@ import (
|
|
|
"ERP_storage/models/Account"
|
|
|
"ERP_storage/models/IOTNetworkCard"
|
|
|
"encoding/json"
|
|
|
+ "fmt"
|
|
|
"github.com/beego/beego/v2/adapter/orm"
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
userlibs "gogs.baozhida.cn/zoie/ERP_libs/User"
|
|
|
"gogs.baozhida.cn/zoie/ERP_libs/lib"
|
|
|
"math"
|
|
|
+ "net/url"
|
|
|
+ "os"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
@@ -404,3 +407,122 @@ func (c *IOTNetworkCardController) IOTNetworkCard_Edit_Device_Number() {
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// 导出
|
|
|
+func (c *IOTNetworkCardController) IOTNetworkCard_Export() {
|
|
|
+
|
|
|
+ // 分页参数 初始化
|
|
|
+
|
|
|
+ // 查询
|
|
|
+ T_name := c.GetString("T_name")
|
|
|
+ T_company_name := c.GetString("T_company_name")
|
|
|
+ T_state, _ := c.GetInt("T_state")
|
|
|
+
|
|
|
+ userList, _ := NatsServer.Read_User_List_All()
|
|
|
+ Account.Read_User_All_Map(userList)
|
|
|
+ IOTNetworkCardDao := IOTNetworkCard.NewIOTNetworkCard(orm.NewOrm())
|
|
|
+ R_List, _ := IOTNetworkCardDao.Read_IOTNetworkCard_List(T_name, T_company_name, T_state, 0, 9999)
|
|
|
+ f := excelize.NewFile() //设置单元格值
|
|
|
+ // 这里设置表头ÒÒ
|
|
|
+ Style1, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Size: 20, Family: "宋体"},
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
|
|
|
+ })
|
|
|
+ Style2, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Size: 15, Family: "宋体"},
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
|
|
|
+ Border: []excelize.Border{
|
|
|
+ {Type: "left", Color: "000000", Style: 1},
|
|
|
+ {Type: "top", Color: "000000", Style: 1},
|
|
|
+ {Type: "bottom", Color: "000000", Style: 1},
|
|
|
+ {Type: "right", Color: "000000", Style: 1},
|
|
|
+ },
|
|
|
+ Fill: excelize.Fill{Type: "pattern", Color: []string{"D9D9D9"}, Pattern: 1},
|
|
|
+ })
|
|
|
+ Style3, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Size: 15, Family: "宋体"},
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
|
|
|
+ Border: []excelize.Border{
|
|
|
+ {Type: "left", Color: "000000", Style: 1},
|
|
|
+ {Type: "top", Color: "000000", Style: 1},
|
|
|
+ {Type: "bottom", Color: "000000", Style: 1},
|
|
|
+ {Type: "right", Color: "000000", Style: 1},
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ f.MergeCell("Sheet1", "A1", "M1")
|
|
|
+ f.SetCellValue("Sheet1", "A1", "物联网卡")
|
|
|
+ f.SetCellStyle("Sheet1", "A1", "M1", Style1)
|
|
|
+
|
|
|
+ // 写入表头
|
|
|
+ headers := []string{"序号", "公司名称", "入库日期", "套餐类型", "套餐", "到期&欠费", "状态", "串码", "移动端设备编号", "MSISDN", "出库日期", "出库项目", "领用人"}
|
|
|
+ for col, header := range headers {
|
|
|
+ cell := fmt.Sprintf("%c%d", rune('A'+col), 2)
|
|
|
+ f.SetCellValue("Sheet1", cell, header)
|
|
|
+ }
|
|
|
+ // 这里设置表头
|
|
|
+ f.SetCellStyle("Sheet1", "A2", "M2", Style2)
|
|
|
+ f.SetRowHeight("Sheet1", 2, 25)
|
|
|
+
|
|
|
+ colsWidth := []float64{6, 40, 15, 12, 12, 25, 12, 30, 17, 17, 15, 30, 15}
|
|
|
+
|
|
|
+ for col, width := range colsWidth {
|
|
|
+ cell := fmt.Sprintf("%c", rune('A'+col))
|
|
|
+ f.SetColWidth("Sheet1", cell, cell, width)
|
|
|
+ }
|
|
|
+ line := 2
|
|
|
+ for i, v := range R_List {
|
|
|
+ // 写入数据
|
|
|
+
|
|
|
+ line++
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_company_name)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_in_date)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_meal_type)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_meal)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_expire)
|
|
|
+ var t_state string
|
|
|
+ switch v.T_State {
|
|
|
+ case 1:
|
|
|
+ t_state = "新卡入库"
|
|
|
+ case 2:
|
|
|
+ t_state = "退还入库"
|
|
|
+ case 3:
|
|
|
+ t_state = "已出库"
|
|
|
+ case 4:
|
|
|
+ t_state = "损坏退还"
|
|
|
+ case 5:
|
|
|
+ t_state = "待注销"
|
|
|
+ case 6:
|
|
|
+ t_state = "已注销"
|
|
|
+ }
|
|
|
+
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), t_state)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_iccid)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v.T_device_number)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.T_MSISDN)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v.T_out_date)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), v.T_out_project)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), v.T_receive_name)
|
|
|
+ }
|
|
|
+
|
|
|
+ f.SetCellStyle("Sheet1", "A3", fmt.Sprintf("M%d", line), Style3)
|
|
|
+
|
|
|
+ timeStr := time.Now().Format("20060102150405")
|
|
|
+ fileName := fmt.Sprintf("物联网卡%v.xlsx", timeStr)
|
|
|
+ filePath := "ofile/" + fileName
|
|
|
+ // 保存文件
|
|
|
+ if err := f.SaveAs(filePath); err != nil {
|
|
|
+ logs.Error("保存文件失败:", err)
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ os.Remove(filePath)
|
|
|
+ }()
|
|
|
+ c.Ctx.Output.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
|
|
|
+ c.Ctx.Output.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName))
|
|
|
+ c.Ctx.Output.Header("Content-Transfer-Encoding", "binary")
|
|
|
+ c.Ctx.Output.Download(filePath, fileName)
|
|
|
+}
|