2
3
lining 6 жил өмнө
parent
commit
e82049ebdc

+ 64 - 0
src/dashoo.cn/backend/api/business/oilsupplier/goodsaptitude/oilgoodsaptitude.go

@@ -179,3 +179,67 @@ type OrganizeSet struct {
 	ClassId     int
 	OrganizeIds []string
 }
+
+type Tmp_OilGoodsAptitude struct {
+	Id                int       `xorm:"not null pk autoincr INT(10)"`
+	ClassId           int       `xorm:"not null default '' comment('编码') INT(11)"`
+	GoodsLevel        string    `xorm:"default '' comment('物资级别') VARCHAR(8)"`
+	GoodsDesc         string    `xorm:"default '' comment('产品说明') VARCHAR(50)"`
+	Standard          string    `xorm:"default '' comment('标准备案') VARCHAR(8)"`
+	CompanyType       string    `xorm:"default '' comment('供应商类型') VARCHAR(50)"`
+	F01               string    `xorm:"default '' VARCHAR(2)"`
+	F02               string    `xorm:"default '' VARCHAR(2)"`
+	F03               string    `xorm:"default '' VARCHAR(2)"`
+	F04               string    `xorm:"default '' VARCHAR(2)"`
+	F05               string    `xorm:"default '' VARCHAR(2)"`
+	F06               string    `xorm:"default '' VARCHAR(2)"`
+	F07               string    `xorm:"default '' VARCHAR(2)"`
+	F08               string    `xorm:"default '' VARCHAR(2)"`
+	F09               string    `xorm:"default '' VARCHAR(2)"`
+	F10               string    `xorm:"default '' VARCHAR(2)"`
+	F11               string    `xorm:"default '' VARCHAR(2)"`
+	F12               string    `xorm:"default '' VARCHAR(2)"`
+	F13               string    `xorm:"default '' VARCHAR(2)"`
+	F14               string    `xorm:"default '' VARCHAR(2)"`
+	F15               string    `xorm:"default '' VARCHAR(2)"`
+	F16               string    `xorm:"default '' VARCHAR(2)"`
+	F17               string    `xorm:"default '' VARCHAR(2)"`
+	F18               string    `xorm:"default '' VARCHAR(2)"`
+	F19               string    `xorm:"default '' VARCHAR(2)"`
+	F20               string    `xorm:"default '' VARCHAR(2)"`
+	F21               string    `xorm:"default '' VARCHAR(2)"`
+	F22               string    `xorm:"default '' VARCHAR(2)"`
+	F23               string    `xorm:"default '' VARCHAR(2)"`
+	F24               string    `xorm:"default '' VARCHAR(2)"`
+	F25               string    `xorm:"default '' VARCHAR(2)"`
+	F26               string    `xorm:"default '' VARCHAR(2)"`
+	F27               string    `xorm:"default '' VARCHAR(2)"`
+	F28               string    `xorm:"default '' VARCHAR(2)"`
+	F29               string    `xorm:"default '' VARCHAR(2)"`
+	F30               string    `xorm:"default '' VARCHAR(2)"`
+	F31               string    `xorm:"default '' VARCHAR(2)"`
+	F32               string    `xorm:"default '' VARCHAR(2)"`
+	F33               string    `xorm:"default '' VARCHAR(2)"`
+	F34               string    `xorm:"default '' VARCHAR(2)"`
+	F35               string    `xorm:"default '' VARCHAR(2)"`
+	F36               string    `xorm:"default '' VARCHAR(2)"`
+	F37               string    `xorm:"default '' VARCHAR(2)"`
+	F38               string    `xorm:"default '' VARCHAR(2)"`
+	F39               string    `xorm:"default '' VARCHAR(2)"`
+	F40               string    `xorm:"default '' VARCHAR(2)"`
+	F41               string    `xorm:"default '' VARCHAR(2)"`
+	F42               string    `xorm:"default '' VARCHAR(2)"`
+	F43               string    `xorm:"default '' VARCHAR(2)"`
+	F44               string    `xorm:"default '' VARCHAR(2)"`
+	F45               string    `xorm:"default '' VARCHAR(2)"`
+	F46               string    `xorm:"default '' VARCHAR(2)"`
+	Edition           string    `xorm:"not null default '' VARCHAR(10)"`
+	Remark            string    `xorm:"comment('备注') VARCHAR(500)"`
+	DeletionStateCode int       `xorm:"default 0 comment('删除状态,0正常,1已删除') INT(10)"`
+	CreateOn          time.Time `xorm:"DATETIME"`
+	CreateUserId      int       `xorm:"INT(10)"`
+	CreateBy          string    `xorm:"VARCHAR(50)"`
+	ModifiedOn        time.Time `xorm:"DATETIME"`
+	ModifiedUserId    int       `xorm:"INT(10)"`
+	ModifiedBy        string    `xorm:"VARCHAR(50)"`
+}

+ 9 - 0
src/dashoo.cn/backend/api/business/oilsupplier/goodsaptitude/oilgoodsaptitudeService.go

@@ -102,4 +102,13 @@ func (s *OilGoodsAptitudeService) GetList_2019(OilGoodsAptitudeName, OilGoodsApt
 	}
 
 	return total
+}
+
+func (s *OilGoodsAptitudeService) GetFCode() string {
+	sql := "select group_concat(Code ORDER BY SortCode) FCodes from `Base_TableHeader` where CategoryCode= '01'"
+	results, err :=s.DBE.QueryString(sql)
+	if err != nil {
+		return ""
+	}
+	return results[0]["FCodes"]
 }

+ 43 - 0
src/dashoo.cn/backend/api/business/oilsupplier/goodsaptitude/oilgoodsaptitudeSession.go

@@ -0,0 +1,43 @@
+package goodsaptitude
+
+import (
+	. "dashoo.cn/backend/api/mydb"
+	"fmt"
+	"github.com/go-xorm/xorm"
+)
+
+type OilGoodsAptitudeSession struct {
+	MySessionBase
+}
+
+func GetOilGoodsAptitudeSession(session *xorm.Session) *OilGoodsAptitudeSession {
+	s := new(OilGoodsAptitudeSession)
+	s.Session = session
+	return s
+}
+
+func (s *OilGoodsAptitudeSession) InstrOilGoodsAptitudeClass(cellsArr []interface{}) {
+
+	for i := 0; i < len(cellsArr); i++ {
+
+	}
+
+	fmt.Println(cellsArr, "==== ")
+
+}
+
+func (s *OilGoodsAptitudeSession) SelectGoodsAptitudeClassCode(code string) string {
+	sql := "select Id from tmp_OilGoodsAptitudeClass where Code='" + code + "'"
+	id, _ := s.Session.QueryString(sql)
+	if id == nil {
+		return ""
+	}
+	return id[0]["Id"]
+}
+
+func (s *OilGoodsAptitudeSession) InsertGoodsAptitude(parentId, fcode, val string) error {
+	sql := "INSERT INTO `tmp_OilGoodsAptitude` (ClassId," + fcode + ") "
+	sql += " VALUES ("+ parentId +"," + val + ")"
+	_, err := s.Session.Query(sql)
+	return err
+}

+ 16 - 0
src/dashoo.cn/backend/api/business/oilsupplier/goodsaptitudeclass/oilgoodsaptitudeclass.go

@@ -26,3 +26,19 @@ type GoodsAptitudeClassList struct {
 	Name     string `xorm:"not null default '' comment('名称') VARCHAR(50)"`
 	ParentId int    `xorm:"not null default 0 comment('上级节点ID') INT(10)"`
 }
+
+type Tmp_OilGoodsAptitudeClass struct {
+	Id                int       `xorm:"not null pk autoincr INT(10)"`
+	Code              string    `xorm:"not null default '' comment('编码') VARCHAR(8)"`
+	Name              string    `xorm:"not null default '' comment('名称') VARCHAR(50)"`
+	ParentId          int       `xorm:"not null default 0 comment('上级节点ID') INT(10)"`
+	Edition           string    `xorm:"not null default '' VARCHAR(10)"`
+	Remark            string    `xorm:"comment('备注') VARCHAR(500)"`
+	DeletionStateCode int       `xorm:"default 0 comment('删除状态,0正常,1已删除') INT(10)"`
+	CreateOn          time.Time `xorm:"DATETIME"`
+	CreateUserId      int       `xorm:"INT(10)"`
+	CreateBy          string    `xorm:"VARCHAR(50)"`
+	ModifiedOn        time.Time `xorm:"DATETIME"`
+	ModifiedUserId    int       `xorm:"INT(10)"`
+	ModifiedBy        string    `xorm:"VARCHAR(50)"`
+}

+ 2 - 0
src/dashoo.cn/backend/api/controllers/base.go

@@ -271,6 +271,8 @@ var (
 	DelOilInfoChangeName                     string = "Del_OilInfoChange"
 	SupplierApplyTimeName                    string = "OilSupplierApplyTime"
 	OilAnnualChangeItemName                  string = "OilAnnualChangeItem"           //信息变更表
+	Tmp_OilGoodsAptitudeName                 string = "tmp_OilGoodsAptitude"
+	Tmp_OilGoodsAptitudeClassName            string = "tmp_OilGoodsAptitudeClass"
 )
 
 //分页信息及数据

+ 112 - 0
src/dashoo.cn/backend/api/controllers/oilsupplier/goodsaptitude.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"github.com/tealeg/xlsx"
+	"log"
 	"os"
 	"reflect"
 	"strconv"
@@ -1073,4 +1074,115 @@ func (this *OilGoodsAptitudeController) ExportExcelAll2019() {
 	this.ServeJSON()
 	elapsed := time.Since(t)
 	fmt.Println(elapsed)
+}
+
+// @Title get 导入excel
+// @Description get SampleType by token
+// @Success 200 {object} sampletype.SampleType
+// @router /importexcel [get]
+func (this *OilGoodsAptitudeController) ImportExcel() {
+
+	t := time.Now()
+
+	url := this.GetString("ExcelUrl")
+
+	_dir := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx"
+	utils.DownloadFile(url, "temp.xlsx", _dir)
+
+	session := utils.DBE.NewSession()
+	err := session.Begin()
+	filePath := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx/temp.xlsx"
+	xlFile, err := xlsx.OpenFile(filePath)
+
+
+	//excelFileName := "F:/物资类项目与资质对照表-2017.xlsx"
+	if err != nil {
+		fmt.Printf("open failed: %s\n", err)
+	}
+	var sheet = xlFile.Sheets[0]
+
+	svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
+	sessionsvc := goodsaptitude.GetOilGoodsAptitudeSession(session)
+	Fstrs := svc.GetFCode()
+	Fstrs = "GoodsLevel,GoodsDesc,Standard,CompanyType," + Fstrs
+	columnArr := strings.Split(Fstrs, ",")
+
+	codemap := make(map[string]int)
+	for i := 3; i < len(sheet.Rows); i++ {
+		cellsArr := sheet.Rows[i].Cells
+
+		parentId := 0
+		classId := 0
+		for j := 0;j < 4; j++ {
+			cellstr := cellsArr[j].String()
+			//fmt.Printf("%s\n", cellstr)
+			if strings.TrimSpace(cellstr) == "" {
+				break
+			}
+			cellArr := strings.Fields(cellstr)
+
+			//id := sessionsvc.SelectGoodsAptitudeClassCode(cellArr[0])
+
+			var entity goodsaptitudeclass.Tmp_OilGoodsAptitudeClass
+			_, has := codemap[cellArr[0]]
+			if !has {
+				if j != 0 {
+					upcellstr := cellsArr[j -1].String()
+					upcellArr := strings.Fields(upcellstr)
+					parentId = codemap[upcellArr[0]]
+				}
+				entity.Code = cellArr[0]
+				entity.Name = cellArr[1]
+				entity.Edition = "1"
+				entity.ParentId = parentId
+				entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
+				entity.CreateBy = this.User.Realname
+				entity.CreateOn = time.Now()
+
+				_, err := sessionsvc.InsertEntityBytbl(Tmp_OilGoodsAptitudeClassName, &entity)
+				if err != nil {
+					session.Rollback()
+					log.Println("Rollback1")
+					elapsed := time.Since(t)
+					fmt.Println(elapsed)
+					return
+				}
+				classId = entity.Id
+				if j != 3 {
+					codemap[cellArr[0]] = entity.Id
+				}
+			}
+		}
+		if strings.TrimSpace(cellsArr[3].String()) != "" {
+			var valstr = ""
+			for k := 4; k < len(cellsArr); k++ {
+				valstr += "'" + cellsArr[k].String() + "',"
+			}
+			valstr = strings.Trim(valstr, ",")
+			valstr = strings.Replace(valstr, "是", "1", -1)
+			log.Println(cellsArr[3].String() + "==" + valstr)
+			var columnstr = ""
+			for l := 0; l < len(cellsArr) - 4; l++ {
+				columnstr += columnArr[l] + ","
+			}
+			columnstr = strings.Trim(columnstr, ",")
+
+			err = sessionsvc.InsertGoodsAptitude(strconv.Itoa(classId), columnstr, valstr)
+			if err != nil {
+				session.Rollback()
+				log.Println("Rollback2")
+				elapsed := time.Since(t)
+				fmt.Println(elapsed)
+				return
+			}
+		}
+
+	}
+	defer func() {
+		session.Close()
+		os.Remove(filePath)
+	}()
+	session.Commit()
+	elapsed := time.Since(t)
+	fmt.Println(elapsed)
 }

+ 5 - 5
src/dashoo.cn/frontend_web/nuxt.config.ignore.js

@@ -160,11 +160,11 @@ module.exports = {
     /* --------Nuxt Start发版用 END-------------- */
   },
   ignore: [
-    // 'pages/oilsupplier/addtionaudit/*.*',
-    // 'pages/oilsupplier/annualaudit/*.*',
-    // 'pages/oilsupplier/badrecord/*.*',
-    // 'pages/oilsupplier/basisbuild/*.*',
-    // 'pages/oilsupplier/compayaudit/*.*',
+    'pages/oilsupplier/addtionaudit/*.*',
+    'pages/oilsupplier/annualaudit/*.*',
+    'pages/oilsupplier/badrecord/*.*',
+    'pages/oilsupplier/basisbuild/*.*',
+    'pages/oilsupplier/compayaudit/*.*',
     // 'pages/oilsupplier/goodsaptitude/*.*',
     'pages/oilsupplier/infochange/*.*',
     'pages/oilsupplier/infochangech/*.*',

+ 7 - 0
src/dashoo.cn/frontend_web/src/api/oilsupplier/goodsaptitude.js

@@ -85,5 +85,12 @@ export default {
       method: 'get',
       params: params
     })
+  },
+  importExcel (params, myAxios) {
+    return myAxios({
+      url: '/goodsaptitude/importexcel',
+      method: 'get',
+      params: params
+    })
   }
 }

+ 90 - 2
src/dashoo.cn/frontend_web/src/pages/oilsupplier/goodsaptitude/index.vue

@@ -15,6 +15,8 @@
           </router-link>
           <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">导入
+          </el-button>
         </span>
         <el-form ref="form" :inline="true" style="float: right; margin-top: -10px">
 
@@ -270,6 +272,19 @@
         <el-button size="mini" type="primary" @click="codeedit">修 改</el-button>
       </span>
     </el-dialog>
+    <el-dialog title="上传文件"  width="600px" :visible.sync="uploadshow">
+      <el-form label-width="100px">
+        <el-row>
+          <el-col :span="12">
+            <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-button size="mini" type="primary" @click="uploadExcel()">导入</el-button>
+          </el-col>
+        </el-row>
+      </el-form>
+    </el-dialog>
   </div>
 </template>
 <script>
@@ -278,8 +293,8 @@
   } from 'vuex'
   import api from '@/api/oilsupplier/goodsaptitude'
   import setapi from '@/api/oilsupplier/oilclassorgset'
-  import FileSaver from 'file-saver';
-  import XLSX from 'xlsx';
+  import axios from 'axios'
+  import uploadajax from '@/assets/js/uploadajax.js'
 
   export default {
     computed: {
@@ -291,6 +306,8 @@
 
     data () {
       return {
+        Excelurl: '',
+        uploadshow: false,
         loading: false,
         codeeditshow: false,
         classid: '',
@@ -528,6 +545,50 @@
       this.getDictOptions()
     },
     methods: {
+      uploadExcel () {
+        let params = {
+          ExcelUrl: this.Excelurl
+        }
+        api.importExcel(params, this.$axios).then(res => {
+
+        })
+      },
+      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
+      },
       Name1Change (val) {
         this.formData.Code2 = this.formData.Code2.replace(/^(\w{0})\w{2}(.*)$/, '$1' + val + '$2')
         this.formData.Code3 = this.formData.Code3.replace(/^(\w{0})\w{2}(.*)$/, '$1' + val + '$2')
@@ -598,6 +659,9 @@
       //   }
       //   return wbout
       // },
+      importExcel () {
+        this.uploadshow = true
+      },
       exportExcel () {
         this.loading = true
         // 显示列
@@ -846,5 +910,29 @@
   .el-col {
     margin-bottom: 5px;
   }
+  .attach-uploader {
+    border: 1px dashed #63B8FF;
+    cursor: pointer;
+    position: relative;
+    overflow: hidden;
+  // margin-bottom: -17px;
+    margin-top: -15px;
+    margin-left: 20px
+  }
+
+  .attach-uploader :hover {
+    border-color: #228B22;
+  }
+  .attach-uploader-icon {
+    font-size: 25px;
+    color: #63B8FF;
+    width: 50px;
+    height: 50px;
+    line-height: 50px;
+    text-align: center;
+  }
 
+  .attach-uploader-icon:hover {
+    color: #228B22;
+  }
 </style>