2
3
Yikoo 5 роки тому
батько
коміт
ee4dec90d5

+ 1 - 1
src/dashoo.cn/backend/api/business/oilcontract/contract/contractService.go

@@ -13,4 +13,4 @@ func GetOilContractService(xormEngine *xorm.Engine) *OilContractService {
 	s := new(OilContractService)
 	s.DBE = xormEngine
 	return s
-}
+}

+ 13 - 0
src/dashoo.cn/backend/api/business/oilcontract/contract/contractSession.go

@@ -0,0 +1,13 @@
+package contract
+import (
+	. "dashoo.cn/backend/api/mydb"
+	"github.com/go-xorm/xorm"
+)
+type OilContractSession struct {
+	MySessionBase
+}
+func GetOilContractSession(session *xorm.Session) *OilContractSession {
+	s := new(OilContractSession)
+	s.Session = session
+	return s
+}

+ 2 - 0
src/dashoo.cn/backend/api/conf/app.conf

@@ -62,6 +62,8 @@ callbackHost=http://localhost:10091/api
 # AposeUrl=http://localhost:8080/acti-api/api/apose
 # BaseUrl=http://localhost:8080/acti-api/api/acti
 
+contractUrl=http://weed1.labsop.cn:9390/6,387ef1cde26d
+
 goodsModuleHost=http://weed1.labsop.cn:9390/6,387ef1cde26d
 basisModuleHost=http://weed1.labsop.cn:9390/4,387f41329d9c
 techModuleHost=http://weed1.labsop.cn:9390/2,388095f31c3d

+ 148 - 0
src/dashoo.cn/backend/api/controllers/oilcontract/contract.go

@@ -2,7 +2,14 @@ package oilcontract
 
 import (
 	"dashoo.cn/backend/api/business/oilcontract/contractReview"
+	"dashoo.cn/backend/api/business/workflow"
 	"encoding/json"
+	"fmt"
+	"github.com/tealeg/xlsx"
+	"log"
+	"os"
+	"reflect"
+	"strconv"
 	"strings"
 	"time"
 
@@ -433,7 +440,148 @@ func (this *OilContractController) GetEntity() {
 	this.Data["json"] = &model
 	this.ServeJSON()
 }
+// @Title 从数据录入数据导出到word文档
+// @Description 数据存入word
+// @Success	200	{object} controllers.Request
+// @router /exportword/:id [post]
+func (this *OilContractController) DocExport() {
+	Id := this.Ctx.Input.Param(":id")
+	var model contract.OilContract
+	svc := contract.GetOilContractService(utils.DBE)
+	svc.GetEntityByIdBytbl(OilContractName, Id, &model)
+
+	var fileName string
+	var Url string
+	Url      = utils.Cfg.MustValue("workflow", "basisModuleHost")
+	fileName = "合同表.docx"
+	svcActiviti := workflow.GetActivitiService(utils.DBE)
+	var data = structToMapDemo(model)
+
+	retDocUrl := svcActiviti.FillWordTemplate(data, Url, fileName)
+	var datainfo ErrorDataInfo
+	datainfo.Code = 0
+	datainfo.Item = retDocUrl
+	datainfo.Message = "打印成功"
+	this.Data["json"] = &datainfo
+	this.ServeJSON()
+}
+
+// @Title get 导入excel
+// @Description 数据存入word
+// @Success 200 {object} controllers.Request
+// @router /importexcel [get]
+func (this *OilContractController) ImportExcel() {
+	url := this.GetString("ExcelUrl")
+	var errorinfo ErrorInfo
+	if url == "" {
+		errorinfo.Code = -2
+		errorinfo.Message = "导入失败!"
+		this.Data["json"] = &errorinfo
+		this.ServeJSON()
+	}
+	session := utils.DBE.NewSession()
+	err := session.Begin()
+	svc := contract.GetOilContractSession(session)
+
+	if err != nil {
+		session.Rollback()
+		errorinfo.Code = -2
+		errorinfo.Message = "导入失败!"
+		this.Data["json"] = &errorinfo
+		this.ServeJSON()
+	}
+
+	_dir := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx"
+	filename := strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
+	utils.DownloadFile(url, filename, _dir)
+	t := time.Now()
+	filePath := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx/" + filename
+	xlFile, err := xlsx.OpenFile(filePath)
+	var errLineNum string
+	//excelFileName := "F:/物资类项目与资质对照表-2017.xlsx"
+	if err != nil {
+		fmt.Printf("open failed: %s\n", err)
+	}
+	var sheet = xlFile.Sheets[0]
+
+	// 插入字段
+	//Fstrs := "ContractNo,ContractName,Amount,ContractType,ContractSonClass,SmallClass,SignedDate,Number,ChooseWay,ContractMark,Currency,BudgetAmount,PerformAmount,IsInternal,IsForeign,IsDeal,MoneyFlows,MoneyChannel,MoneyChannelSon,MoneyChannelSmall,SingUnit,Place,StartDate,EndDate,DisputeResolution,Remark,ProjectOwner,SubmitDate,SealName,PoNumber"
+	//columnArr := strings.Split(Fstrs, ",")
+
+	defer func() {
+		session.Close()
+	}()
+
+	codemap := make(map[string](map[string]int))
+	for i := 1; i < len(sheet.Rows); i++ {
+		lineNo := strconv.Itoa(i + 1)
+		fmt.Println(lineNo)
+
+
+
+		//this.OperationCell(svc, lineNo, columnArr, sheet.Rows[i].Cells, &errLineNum)
 
+
+	}
+
+	os.Remove(filePath)
+	if errLineNum != "" {
+		session.Rollback()
+		errorinfo.Code = -1
+		errorinfo.Message = "导入失败!错误行号:" + errLineNum
+		this.Data["json"] = &errorinfo
+		this.ServeJSON()
+	} else {
+		session.Commit()
+		elapsed := time.Since(t)
+		log.Println(elapsed)
+		errorinfo.Code = 0
+		errorinfo.Message = "导入成功!"
+		this.Data["json"] = &errorinfo
+		this.ServeJSON()
+	}
+}
+
+func (this *OilContractController) OperationCell(svc *contract.OilContractSession, lineNo string, columnArr []string, cellsArr []*xlsx.Cell, errLineNum *string) {
+
+	defer func() {
+		if err := recover(); err != nil {
+			log.Println("err"+lineNo, err)
+			*errLineNum += lineNo + ","
+		}
+	}()
+	cellsArrLen := len(cellsArr)
+	var valstr = ""
+
+	for i := 0; i < cellsArrLen;i++ {
+		valstr += "'" + cellsArr[i].String() + "',"
+	}
+	valstr = strings.Trim(valstr, ",")
+	valstr = strings.Replace(valstr, "是", "1", -1)
+	log.Println(cellsArr[6].String() + "==" + valstr)
+	var columnstr= ""
+	for l := 0; l < cellsArrLen; l++ {
+		columnstr += columnArr[l] + ","
+	}
+	columnstr = strings.Trim(columnstr, ",")
+
+	//err := svc.InsertTmpOilBasisBuild(columnstr, valstr)
+	//if err != nil {
+	//	panic(err)
+	//}
+
+}
+
+
+func structToMapDemo(obj interface{}) map[string]interface{} {
+	obj1 := reflect.TypeOf(obj)
+	obj2 := reflect.ValueOf(obj)
+	var data = make(map[string]interface{})
+	for i := 0; i < obj1.NumField(); i++ {
+		data[obj1.Field(i).Name] = obj2.Field(i).Interface()
+	}
+	return data
+}
 // @Title 添加
 // @Description 新增
 // @Param 	body body oilcontract.OilContract

+ 8 - 0
src/dashoo.cn/frontend_web/src/api/oilcontract/contract.js

@@ -183,4 +183,12 @@ export default {
       method: 'delete'
     })
   },
+
+  importExcel (params, myAxios) {
+    return myAxios({
+      url: '/contract/importexcel',
+      method: 'get',
+      params: params
+    })
+  },
 }

+ 87 - 3
src/dashoo.cn/frontend_web/src/pages/oilcontract/contract-import/index.vue

@@ -15,7 +15,7 @@
           <router-link :to="'/oilcontract/contract-import/add/operation'">
             <el-button type="primary" size="mini" style="margin-left:10px; margin-top: -4px;">添加</el-button>
           </router-link>
-          <el-button type="primary" size="mini" style="margin-left:10px; margin-top: -4px;">导入</el-button>
+          <el-button type="primary" size="mini" @click="importExcel" style="margin-left:10px; margin-top: -4px;">导入</el-button>
           <!-- <el-button type="primary" size="mini" style="margin-left:10px; margin-top: -4px;">分发给二级单位评价</el-button> -->
         </span>
         <el-form ref="form" :inline="true" style="float: right; margin-top: -10px">
@@ -250,14 +250,30 @@
       </span>
     </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>
   </div>
 </template>
 <script>
   import { mapGetters } from 'vuex';
   import api from '@/api/oilcontract/contract';
   import permissionApi from '@/api/oilcontract/permission';
-
-
+  import axios from 'axios'
+  import uploadajax from '@/assets/js/uploadajax.js'
   export default {
     computed: {
       ...mapGetters({
@@ -308,6 +324,13 @@
 
     data() {
       return {
+        uploadshow: false,
+        Excelurl: '',
+        importDialogVisible: false,
+        importloading: false,
+        showimportvisible: false,
+
+
         evaluateBoolean:false,
         deleteBoolean:false,
         // 控制删除框
@@ -750,6 +773,67 @@
         var minute = date.getMinutes();
         minute = minute < 10 ? ('0' + minute) : minute;
         return y + '-' + m + '-' + d + ' ' + h + ':' + minute;
+      },
+
+      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: '未上传成功!请重新上传!'
+              })
+            })
+        }
+      },
+
+
+      // 导入
+      uploadExcel () {
+        this.importloading = true
+        this.uploadshow = false
+        let params = {
+          ExcelUrl: this.Excelurl
+        }
+        api.importExcel(params, this.$axios).then(res => {
+          this.importloading = false
+          if (res.data.code === 0) {
+            this.$message({
+              type: 'success',
+              message: res.data.message
+            })
+            this.initDatas()
+          } else if (res.data.code === -1) {
+            this.errorDialogVisible = true
+            this.textarea = res.data.message
+          } else if (res.data.code === -2) {
+            this.$message({
+              type: 'warning',
+              message: res.data.message
+            })
+          }
+        })
       }
     }
   }