|
|
@@ -9,6 +9,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/tealeg/xlsx"
|
|
|
+ "log"
|
|
|
"os"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
@@ -257,6 +258,58 @@ func (this *OilCatalogController) ExportExcelAll() {
|
|
|
this.ServeJSON()
|
|
|
}
|
|
|
|
|
|
+// @Title get 导出ex --收入业务
|
|
|
+// @Description get SampleType by token
|
|
|
+// @Success 200 {object} sampletype.SampleType
|
|
|
+// @router /exportexcelincome [get]
|
|
|
+func (this *OilCatalogController) ExportExcelIncome() {
|
|
|
+
|
|
|
+ //CardTitle := this.GetString("CardTitle")
|
|
|
+ CatalogType := this.GetString("CatalogType")
|
|
|
+
|
|
|
+ svc := oilcatalog.GetOilCatalogService(utils.DBE)
|
|
|
+ var list []oilcatalog.OilCatalog
|
|
|
+ where := "CatalogType=" + CatalogType
|
|
|
+ svc.GetEntities(&list, where)
|
|
|
+
|
|
|
+ filetitle := "大港油田收入业务目录"
|
|
|
+ showcolumnarr := "企业名称,法人姓名,法人身份证号,企业注册地址,全国统一信用代码,注册资本,申请备案范围,备注"
|
|
|
+
|
|
|
+ f := xlsx.NewFile()
|
|
|
+ sheet, _ := f.AddSheet(filetitle)
|
|
|
+ cellname := strings.Split(showcolumnarr, ",")
|
|
|
+ row := sheet.AddRow()
|
|
|
+ row.WriteSlice(&cellname, -1)
|
|
|
+
|
|
|
+ for _, item := range list {
|
|
|
+ datastring := item.CompanyName + "," + item.LegalPerson + "," + item.IDCode + "," + item.Address + "," + item.USCCode +
|
|
|
+ "," + strconv.FormatFloat(item.RegCapital, 'f', 2, 64) + "," + item.RecordScope + "," + item.Remark
|
|
|
+ cellname := strings.Split(datastring, ",")
|
|
|
+ row := sheet.AddRow()
|
|
|
+ row.WriteSlice(&cellname, -1)
|
|
|
+ }
|
|
|
+ for c, cl := 0, len(sheet.Cols); c < cl; c++ {
|
|
|
+ sheet.Cols[c].Width = 20
|
|
|
+ }
|
|
|
+ dir := "static/file/excel/report/" + this.GetAccode()
|
|
|
+ SaveDirectory(dir)
|
|
|
+ path := dir + "/" + utils.TimeFormat(time.Now(), "20060102") + filetitle + ".xlsx"
|
|
|
+ f.Save(path)
|
|
|
+ var sw *Seaweed
|
|
|
+ var filer []string
|
|
|
+ if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
|
|
|
+ filer = []string{_filer}
|
|
|
+ }
|
|
|
+ sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
|
|
|
+ _, _, fID, _ := sw.UploadFile(path, "", "")
|
|
|
+
|
|
|
+ retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
|
|
|
+ os.Remove(path)
|
|
|
+ fmt.Println("==retDocWatermarkUrl==", retDocUrl)
|
|
|
+ this.Data["json"] = retDocUrl
|
|
|
+ this.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
// @Title
|
|
|
// @Description
|
|
|
// @Success 200 {object} controllers.Request
|
|
|
@@ -276,4 +329,90 @@ func (this *OilCatalogController) IsAccess() {
|
|
|
|
|
|
this.Data["json"] = res
|
|
|
this.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title get 导入excel
|
|
|
+// @Description get SampleType by token
|
|
|
+// @Success 200 {object} sampletype.SampleType
|
|
|
+// @router /importexcel [get]
|
|
|
+func (this *OilCatalogController) ImportExcel() {
|
|
|
+
|
|
|
+ t := time.Now()
|
|
|
+
|
|
|
+ url := this.GetString("ExcelUrl")
|
|
|
+ CatalogType := this.GetString("CatalogType")
|
|
|
+ var errorinfo ErrorInfo
|
|
|
+ if url == "" {
|
|
|
+ errorinfo.Code = -2
|
|
|
+ errorinfo.Message = "导入失败,文件未上传成功"
|
|
|
+ this.Data["json"] = &errorinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ svc := oilcatalog.GetOilCatalogService(utils.DBE)
|
|
|
+
|
|
|
+ log.Printf("url:==" + url) // http://60.30.245.229//upfile/dc1/2,063156edd288
|
|
|
+ extranetIP := utils.Cfg.MustValue("server", "extranetIP")
|
|
|
+ localIP := utils.Cfg.MustValue("server", "localIP")
|
|
|
+ if strings.Index(url, extranetIP) >= 0 {
|
|
|
+ url = strings.Replace(url, extranetIP, localIP, 1)
|
|
|
+ }
|
|
|
+ _dir := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx"
|
|
|
+ filename := strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
|
|
|
+ utils.DownloadFile(url, filename, _dir)
|
|
|
+
|
|
|
+ filePath := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx/" + filename
|
|
|
+ xlFile, err := xlsx.OpenFile(filePath)
|
|
|
+
|
|
|
+ //excelFileName := "F:/物资类项目与资质对照表-2017.xlsx"
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("open failed: %s\n", err)
|
|
|
+ }
|
|
|
+ var sheet = xlFile.Sheets[0]
|
|
|
+ errLineNo := ""
|
|
|
+ for i := 1; i < len(sheet.Rows); i++ {
|
|
|
+ cells := sheet.Rows[i].Cells
|
|
|
+ if len(cells) != 0 {
|
|
|
+ if cells[1].Value != "" {
|
|
|
+ ValidityFrom, err1 := time.Parse("2006-01-02", cells[3].Value)
|
|
|
+ ValidityTo, err2 := time.Parse("2006-01-02", cells[4].Value)
|
|
|
+ CompanyName := cells[1].Value
|
|
|
+ Business := cells[2].Value
|
|
|
+ Remark := cells[5].Value
|
|
|
+ if err1 != nil || err2 != nil {
|
|
|
+ errLineNo = errLineNo + "," + strconv.Itoa(i)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ var model oilcatalog.OilCatalog
|
|
|
+ model.CatalogType, _ = strconv.Atoi(CatalogType)
|
|
|
+ model.CompanyName = CompanyName
|
|
|
+ model.Business = Business
|
|
|
+ model.ValidityFrom = ValidityFrom
|
|
|
+ model.ValidityTo = ValidityTo
|
|
|
+ model.Remark = Remark
|
|
|
+ where := "CatalogType=" + CatalogType + " and CompanyName='" + CompanyName + "'"
|
|
|
+ has := svc.GetEntity(&model, where)
|
|
|
+ if !has {
|
|
|
+ svc.InsertEntity(&model)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ os.Remove(filePath)
|
|
|
+ elapsed := time.Since(t)
|
|
|
+ fmt.Println(elapsed)
|
|
|
+ if len(errLineNo) > 0 {
|
|
|
+ errorinfo.Code = -1
|
|
|
+ errorinfo.Message = "导入完成!错误行号:" + errLineNo
|
|
|
+ this.Data["json"] = &errorinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ } else {
|
|
|
+ errorinfo.Code = 0
|
|
|
+ errorinfo.Message = "导入完成!"
|
|
|
+ this.Data["json"] = &errorinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|