2
3
lining 5 rokov pred
rodič
commit
e383f78dc1

+ 139 - 0
src/dashoo.cn/backend/api/controllers/oilsupplier/oilcatalog.go

@@ -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()
+	}
+
+
 }

+ 14 - 0
src/dashoo.cn/frontend_web/src/api/oilsupplier/oilcatalog.js

@@ -33,11 +33,25 @@ export default {
       params: params
     })
   },
+  exportExcelIncome (params, myAxios) {
+    return myAxios({
+      url: '/oilcatalog/exportexcelincome',
+      method: 'get',
+      params: params
+    })
+  },
   isAccess (params, myAxios) {
     return myAxios({
       url: '/oilcatalog/isaccess',
       method: 'get',
       params: params
     })
+  },
+  importExcel (params, myAxios) {
+    return myAxios({
+      url: '/oilcatalog/importexcel',
+      method: 'get',
+      params: params
+    })
   }
 }

+ 1 - 2
src/dashoo.cn/frontend_web/src/pages/oilsupplier/oilcatalog/income.vue

@@ -246,10 +246,9 @@
         }
         this.loading = true
         let params = {
-          CardTitle: this.cardTitle,
           CatalogType: this.formData.CatalogType
         }
-        api.exportExcelAll(params, this.$axios).then(res => {
+        api.exportExcelIncome(params, this.$axios).then(res => {
           this.loading = false
           let docurl = res.data
           // 内网服务器专用

+ 93 - 0
src/dashoo.cn/frontend_web/src/pages/oilsupplier/oilcatalog/index.vue

@@ -41,6 +41,7 @@
             <el-button type="primary" size="mini" style="margin-left:10px; margin-top: -4px;" v-if="formData.CatalogType == '7'">收入业务申请</el-button>
             <el-button type="primary" size="mini" @click="addOilcatalog" v-if="showBtn">添加</el-button>
             <el-button type="primary" size="mini" style="margin-left:10px; margin-top: -4px;" @click="exportExcel">导出</el-button>
+            <el-button type="primary" size="mini" style="margin-left:10px; margin-top: -4px;" @click="importExcel" v-if="showBtn">导入</el-button>
           </el-form-item>
         </el-form>
       </div>
@@ -115,11 +116,31 @@
       </el-form>
     </el-dialog>
 
+    <el-dialog title="上传文件"  width="600px" :visible.sync="uploadshow">
+      <el-form label-width="100px">
+        <el-row>
+          <el-col :span="24">
+            <el-upload multiple style="margin-top: 10px;" action="" ref="refuploadattach"
+                       :http-request="uploadrequest" :before-upload="beforeAvatarUpload">
+              <el-button size="small" type="primary">点击上传</el-button>
+            </el-upload>
+          </el-col>
+          <el-col :span="24">
+            <el-button style="float: right;" size="mini" type="primary" @click="uploadExcel()">确定</el-button>
+          </el-col>
+        </el-row>
+      </el-form>
+    </el-dialog>
+    <el-dialog title="导入完成" :visible.sync="errorDialogVisible" :close-on-click-modal = "false" width="720px">
+      <el-input type="textarea" autosize placeholder="请输入内容" v-model="textarea"></el-input>
+    </el-dialog>
   </div>
 </template>
 <script>
   import { mapGetters } from 'vuex'
   import api from '@/api/oilsupplier/oilcatalog'
+  import axios from 'axios'
+  import uploadajax from '@/assets/js/uploadajax.js'
 
   export default {
     computed: {
@@ -139,6 +160,7 @@
       }
 
       return {
+        Excelurl: '',
         btnName: '打开',
         showBtn: false,
         cardTitle: '',
@@ -146,6 +168,9 @@
         addShowTitle: '添加目录',
         addshow: false,
         loading: false,
+        uploadshow: false,
+        errorDialogVisible: false,
+        textarea: '',
 
         // 分页参数
         size: 10,
@@ -229,6 +254,74 @@
     },
 
     methods: {
+      // excel导入
+      importExcel () {
+        this.uploadshow = true
+      },
+      uploadrequest (option) {
+        let _this = this
+        if (process.client) {
+          const myDomain = window.location.host
+          axios.post(process.env.upfilehost, {})
+            .then(function (res) {
+              if (res.data && res.data.fid && res.data.fid !== '') {
+                if (res.data.publicUrl.indexOf('/upfile') === 0) {
+                  option.action = `http://${myDomain}/${res.data.publicUrl}/${res.data.fid}`
+                } else {
+                  option.action = `http://${res.data.publicUrl}/${res.data.fid}`
+                }
+                uploadajax(option)
+                _this.Excelurl = option.action
+              } else {
+                _this.$message({
+                  type: 'warning',
+                  message: '未上传成功!请刷新界面重新上传!'
+                })
+              }
+            })
+            .catch(res => {
+              _this.$message({
+                type: 'warning',
+                message: '未上传成功!请重新上传!'
+              })
+            })
+        }
+      },
+      beforeAvatarUpload (file) {
+        if (file.name.indexOf('.xlsx') < 0) {
+          this.$message.error('文件格式必须为.xlsx')
+          return false
+        }
+        return true
+      },
+      uploadExcel () {
+        this.importloading = true
+        this.uploadshow = false
+        let params = {
+          ExcelUrl: this.Excelurl,
+          CatalogType: this.formData.CatalogType
+        }
+        api.importExcel(params, this.$axios).then(res => {
+          this.importloading = false
+          this.initDatas()
+          if (res.data.code === 0) {
+            this.$message({
+              type: 'success',
+              message: res.data.message
+            })
+          } else if (res.data.code === -1) {
+            this.initDatas()
+            this.errorDialogVisible = true
+            this.textarea = res.data.message
+          } else if (res.data.code === -2) {
+            this.$message({
+              type: 'warning',
+              message: res.data.message
+            })
+          }
+        })
+      },
+
       isAccess () {
         let params = {
           RoleId: '10000203'