package oilsupplier import ( "dashoo.cn/backend/api/business/oilsupplier/suppliercert" "dashoo.cn/backend/api/business/oilsupplier/supplierdataentry" "dashoo.cn/backend/api/business/oilsupplier/tableheader" "dashoo.cn/backend/api/business/workflow" "encoding/json" "fmt" "github.com/tealeg/xlsx" "log" "os" "reflect" "strconv" "strings" "time" "dashoo.cn/backend/api/business/items" "dashoo.cn/backend/api/business/baseUser" "dashoo.cn/business2/userRole" //"dashoo.cn/backend/api/business/items" "dashoo.cn/backend/api/business/oilsupplier/basisbuild" "dashoo.cn/backend/api/business/oilsupplier/goodsaptitude" "dashoo.cn/backend/api/business/oilsupplier/supplierfile" "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub" "dashoo.cn/backend/api/business/oilsupplier/supplier" "dashoo.cn/business2/parameter" . "dashoo.cn/backend/api/controllers" "dashoo.cn/utils" . "github.com/linxGnu/goseaweedfs" ) type OilBasisBuildController struct { BaseController } // @Title 获取列表 // @Description get user by token // @Success 200 {object} []basisbuild.OilBasisBuild // @router /list [get] func (this *OilBasisBuildController) GetEntityList() { //获取分页信息 page := this.GetPageInfoForm() where := " 1=1 " orderby := "Code" asc := true Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = Prop if Order == "asc" { asc = true }else { asc = false } } CreateOn := this.GetString("CreateOn") Code := this.GetString("Code") Name := this.GetString("Name") if Code != "" { where = where + " and Code like '%" + Code + "%'" } if Name != "" { where = where + " and Name like '%" + Name + "%'" } if CreateOn != "" { dates := strings.Split(CreateOn, ",") if len(dates) == 2 { minDate := dates[0] maxDate := dates[1] where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'" } } svc := basisbuild.GetOilBasisBuildService(utils.DBE) var list []basisbuild.OilBasisBuild total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total datainfo.PageIndex = page.CurrentPage datainfo.ItemsPerPage = page.Size this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取字典列表 // @Description get user by token // @Success 200 {object} map[string]interface{} // @router /dictlist [get] func (this *OilBasisBuildController) GetDictList() { dictList := make(map[string]interface{}) dictSvc := items.GetItemsService(utils.DBE) userSvc := baseUser.GetBaseUserService(utils.DBE) //customerSvc := svccustomer.GetCustomerService(utils.DBE) //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", "") var userEntity userRole.Base_User userSvc.GetEntityById(this.User.Id, &userEntity) dictList["Supervisers"] = userSvc.GetUserListByDepartmentId("", userEntity.Departmentid) dictList["AuditStep"] = dictSvc.GetKeyValueItems("AuditStep", this.User.AccCode) //var dictCustomer []svccustomer.Customer //customerSvc.GetEntitysByWhere("" + CustomerName, "", &dictCustomer) //dictList["EntrustCorp"] = &dictCustomer var datainfo DataInfo datainfo.Items = dictList this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取实体 // @Description 获取实体 // @Success 200 {object} basisbuild.OilBasisBuild // @router /get/:id [get] func (this *OilBasisBuildController) GetEntity() { Id := this.Ctx.Input.Param(":id") var model basisbuild.OilBasisBuild svc := basisbuild.GetOilBasisBuildService(utils.DBE) svc.GetEntityByIdBytbl(""+OilBasisBuildName, Id, &model) this.Data["json"] = &model this.ServeJSON() } // @Title 添加 // @Description 新增 // @Success 200 {object} controllers.Request // @router /add [post] func (this *OilBasisBuildController) AddEntity() { var model basisbuild.OilBasisBuild var jsonBlob = this.Ctx.Input.RequestBody svc := basisbuild.GetOilBasisBuildService(utils.DBE) json.Unmarshal(jsonBlob, &model) model.CreateOn = time.Now() model.CreateBy = this.User.Realname model.CreateUserId, _ = utils.StrTo(this.User.Id).Int() //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int() _, err := svc.InsertEntityBytbl(""+OilBasisBuildName, &model) var errinfo ErrorDataInfo if err == nil { //新增 errinfo.Message = "添加成功!" errinfo.Code = 0 errinfo.Item = model.Id this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 修改实体 // @Description 修改实体 // @Success 200 {object} controllers.Request // @router /update/:id [post] func (this *OilBasisBuildController) UpdateEntity() { id := this.Ctx.Input.Param(":id") var errinfo ErrorInfo if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var model basisbuild.OilBasisBuild var basmodel []basisbuild.OilBasisBuild svc := basisbuild.GetOilBasisBuildService(utils.DBE) var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &model) if model.Name != "" { where := " Name = '" + model.Name +"' and Id not in ('"+id+"')" svc.GetEntitysByWhere(OilBasisBuildName, where, &basmodel) if len(basmodel) > 0 { errinfo.Message = "名称已存在,请重新添加!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } } if model.Code != "" { cowhere := " Code = '" + model.Code+"' and Id not in ('"+id+"')" svc.GetEntitysByWhere(OilBasisBuildName, cowhere, &basmodel) if len(basmodel) > 0 { errinfo.Message = "编码已存在,请重新添加!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } } model.ModifiedOn = time.Now() model.ModifiedBy = this.User.Realname model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() cols := []string{ "Id", "Code", "Name", "F01", "F02", "F03", "F04", "F05", "F06", "F07", "F08", "F09", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24", "F25", "Remark", "DeletionStateCode", "CreateOn", "CreateUserId", "CreateBy", "ModifiedOn", "ModifiedUserId", "ModifiedBy", } err := svc.UpdateEntityBytbl(""+OilBasisBuildName, id, &model, cols) if err == nil { errinfo.Message = "修改成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 删除单条信息 // @Description // @Success 200 {object} ErrorInfo // @Failure 403 :id 为空 // @router /delete/:Id [delete] func (this *OilBasisBuildController) DeleteEntity() { Id := this.Ctx.Input.Param(":Id") var errinfo ErrorInfo if Id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var model basisbuild.OilBasisBuild var entityempty basisbuild.OilBasisBuild svc := basisbuild.GetOilBasisBuildService(utils.DBE) opdesc := "删除-" + Id err := svc.DeleteOperationAndWriteLogBytbl(""+OilBasisBuildName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "钻井日报") if err == nil { errinfo.Message = "删除成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 基建类业务 // @Description get user by token // @Success 200 {object} models.Userblood // @router /basiclist [get] func (this *OilBasisBuildController) BasicList() { page := this.GetPageInfoForm() var list []basisbuild.OilBasisBuild svc := basisbuild.GetOilBasisBuildService(utils.DBE) where := " 1=1" orderby := "Id" asc := true Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = Prop if Order == "asc" { asc = true } } keyword := this.GetString("keyword") if keyword != "" { where = where + " and Name like '%" + keyword + "%' or Code like '%" + keyword + "%'" } total := svc.GetPagingEntitiesWithoutAccCode(page.CurrentPage, page.Size, orderby, asc, &list, where) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total this.Data["json"] = &datainfo this.ServeJSON() } // @Title get 导出ex // @Description get SampleType by token // @Success 200 {object} sampletype.SampleType // @router /exportexcelall [get] func (this *OilBasisBuildController) ExportExcelAll() { //获取分页信息 where := " 1=1 " orderby := "Code" asc := true Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = Prop if Order == "asc" { asc = true } else { asc = false } } t := time.Now() svc := basisbuild.GetOilBasisBuildService(utils.DBE) var list []basisbuild.OilBasisBuild svc.GetPagingEntitiesWithOrderBytbl("", 0, 0, orderby, asc, &list, where) var title []string filetitle := "基建类" //自定义显示列 showcolumnarr := this.GetString("showcolumnarr") showcolumnnamearr := this.GetString("showcolumnnamearr") titlestring := showcolumnnamearr title = strings.Split(titlestring, ",") f := xlsx.NewFile() sheet, _ := f.AddSheet(filetitle) cellname := strings.Split(showcolumnarr, ",") row := sheet.AddRow() row.WriteSlice(&cellname, -1) for _, item := range list { var enumModel basisbuild.OilBasisBuild tmpModel := &item enumModel = *tmpModel immumodel := reflect.ValueOf(&enumModel) elem := immumodel.Elem() row := sheet.AddRow() for _, name := range title { cell := row.AddCell() if strings.HasPrefix(name, "F") { var val = elem.FieldByName(name).String() if val == "1" { cell.Value = "是" } else { cell.Value = "" } } else { cell.Value = elem.FieldByName(name).String() } } } 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(), "200612") + 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() elapsed := time.Since(t) fmt.Println(elapsed) } // @Title 获取所有 // @Description // @Success 200 {object} // @router /getcompanylist [post] func (this *OilBasisBuildController) GetTList() { var model supplier.OilSupplierSelect var model1 supplier.RegCapitalRange //注册资金范围 //var model2 supplier.NeedFileTypeStruct //资质结构体 var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &model) json.Unmarshal(jsonBlob, &model1) //json.Unmarshal(jsonBlob, &model2) // //获取分页信息 page := this.GetPageInfoForm() where := " 1=1 AND b.InFlag in (1,2,3) AND b.Status = '8' and b.SupplierTypeCode = '02' AND t.SupplierId IS NOT NULL " orderby := "a.Id" asc := true Order := this.GetString("Order") Prop := this.GetString("Prop") CheckUId := this.GetString("CheckUId") FullId := this.GetString("FullId") if Order != "" && Prop != "" { orderby = Prop if Order == "desc" { asc = false } } leftjoin := "" //准入证号 if model.AccessCardNo != "" { where = where + " and b.AccessCardNo like '%" + model.AccessCardNo + "%'" } //企业名称 if model.SupplierName != "" { where = where + " and a.SupplierName like '%" + model.SupplierName + "%'" } if model.OldSupplierName != "" { where = where + " and OldSupplierName like '%" + model.OldSupplierName + "%'" } if FullId != "" { where = where + " and f.Id = '" + FullId + "'" } if CheckUId != "" { where = where + " and g.CheckUnitId = '" + CheckUId + "'" } //准入标识 1 准入 2 暂停 3取消 if model.InFlag != "" { where = where + " and b.InFlag = '" + model.InFlag + "'" } //法人 if model.LegalPerson != "" { where = where + " and a.LegalPerson like '%" + model.LegalPerson + "%'" } //联系人 if model.ContactName != "" { where = where + " and a.ContactName like '%" + model.ContactName + "%'" } //统一社会信用代码 if model.CommercialNo != "" { where = where + " and a.CommercialNo like '%" + model.CommercialNo + "%'" } //开户银行 if model.DepositBank != "" { where = where + " and a.DepositBank like '%" + model.DepositBank + "%'" } //HSE审查 if model.HseTraining != "" { where = where + " and a.HseTraining = '" + model.HseTraining + "'" } //公司类型 if model.CompanyType != "" { where = where + " and a.CompanyType like '%" + model.CompanyType + "%'" } //成立时间 SetupTime := this.GetString("SetupTime") if SetupTime != "" { where = where + " and a.SetupTime ='" + SetupTime + "'" } //注册资金范围 if model1.RegCapital1 != "" { where = where + " and a.RegCapital >= '" + model1.RegCapital1 + "'" } if model1.RegCapital2 != "" { where = where + " and a.RegCapital <= '" + model1.RegCapital2 + "'" } //注册省份 if model.Province != "" { where = where + " and a.Province = '" + model.Province + "'" } //注册市 if model.City != "" { where = where + " and a.City = '" + model.City + "'" } //注册区 if model.Street != "" { where = where + " and a.Street = '" + model.Street + "'" } //注册详细地址 if model.Address != "" { where = where + " and a.Address like '%" + model.Address + "%'" } if model.LinkProvince != "" { where = where + " and a.LinkProvince = '" + model.LinkProvince + "'" } if model.LinkCity != "" { where = where + " and a.LinkCity = '" + model.LinkCity + "'" } if model.LinkStreet != "" { where = where + " and a.LinkStreet = '" + model.LinkStreet + "'" } if model.LinkAddress != "" { where = where + " and a.LinkAddress like '%" + model.LinkAddress + "%'" } //营业范围 if model.BusinessScope != "" { where = where + " and a.BusinessScope like '%" + model.BusinessScope + "%'" } CreateOn := this.GetString("CreateOn") if CreateOn != "" { dates := strings.Split(CreateOn, ",") if len(dates) == 2 { minDate := dates[0] maxDate := dates[1] where = where + " and a.CreateOn>='" + minDate + "' and a.CreateOn<='" + maxDate + "'" } } a := model.InStyle fmt.Println(a) //准入方式 if model.InStyle != "" { if model.InStyle == "0"{ where = where + " and b.InStyle in ('2','3','4','5')" }else{ where = where + " and b.InStyle ='" + model.InStyle + "'" } } having:="" //准入范围 if model.CerSubName!="" { having = " having CerSubName like '%"+model.CerSubName+"%' " leftjoin = "left join "+ OilSupplierCertSubName + " d on d.SupplierCertId = b.Id " } //资质 if model.NeedFileType!="" { having = " having NeedFileType like '%"+model.NeedFileType+"%' " } if model.CerSubName!=""&& model.NeedFileType!=""{ having = " having CerSubName like '%"+model.CerSubName+"%' and NeedFileType like '%"+model.NeedFileType+"%' " leftjoin = "left join "+ OilSupplierCertSubName + " d on d.SupplierCertId = b.Id " } svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE) var list []supplier.OilSupplierSelect total := svc.GetMyPagingDelEntitiesWithOrderBytbl(OilSupplierName, OilSupplierCertName, OilInfoChangeName,OilCorporateInfoName,OilSupplierCertSubName, OilSupplierFileName, page.CurrentPage, page.Size, orderby, asc, &list, where,having, leftjoin) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total datainfo.PageIndex = page.CurrentPage datainfo.ItemsPerPage = page.Size this.Data["json"] = &datainfo this.ServeJSON() } // @Title 删除不符合的的准入项 // @Description get user by token // @Success 200 {object} []suppliercertsub.OilSupplierCertSub // @router /deltmpsuppliercertsub [get] func (this *OilBasisBuildController) DelTmpSupplierCertSub() { var err error session := utils.DBE.NewSession() session.Begin() defer session.Close() supplierId := this.GetString("SupplierId") id := this.GetString("Id") svc := goodsaptitude.GetOilGoodsAptitudeSession(session) var supplierCertSubList []suppliercertsub.Tmp_OilSupplierCertSub wheredel := "1=1 and SupplierTypeCode = '02'" if supplierId != "" { wheredel += " and SupplierId=" + supplierId } if id != "" { wheredel += " and Id=" + id } svc.GetEntitysByWhere(TmpOilSupplierCertSubName, wheredel, &supplierCertSubList) var errinfo ErrorInfo for _,item := range supplierCertSubList { where := "Id = " + strconv.Itoa(item.Id) err = svc.DeleteEntityBytbl(OilSupplierCertSubName, where) if err != nil { session.Rollback() errinfo.Code = -1 errinfo.Message = "删除失败!" this.Data["json"] = &errinfo this.ServeJSON() } } for _,item := range supplierCertSubList { where := "Id = " + strconv.Itoa(item.Id) err = svc.DeleteEntityBytbl(TmpOilSupplierCertSubName, where) } if err == nil { session.Commit() errinfo.Code = 0 errinfo.Message = "删除成功!" this.Data["json"] = &errinfo this.ServeJSON() } else { session.Rollback() errinfo.Code = -1 errinfo.Message = "删除失败!" this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 修改资质后找出不符合的准入 // @Description 修改实体 // @Success 200 {object} controllers.Request // @router /findinconformity [post] func (this *OilBasisBuildController) FindInconformity() { var errinfo ErrorInfo var err error var model basisbuild.OilBasisBuild var companygoodslist []suppliercertsub.OilSupplierCertSub var companygood suppliercertsub.OilSupplierCertSub var SurplusList []supplierfile.FileList var supfilemodel []supplierfile.OilSupplierFile var supfilemodel01 []supplierfile.OilSupplierFile svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE) filesvc := supplierfile.GetSupplierfileService(utils.DBE) paramSvc := baseparameter.GetBaseparameterService(utils.DBE) var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &model) Code := model.Code where := " Code ='"+Code+"' and Type in ('1','3') and SupplierTypeCode = '02'" svc.FindGoodsByCode("OilSupplierCertSub",where,&companygoodslist) SurplusList = filesvc.GetBasicNeedFileList(strconv.Itoa(model.Id)) for _, CertSub := range companygoodslist { companygood = CertSub wherecompany := " SupplierId ="+strconv.Itoa(CertSub.SupplierId) svc.FindFileByCompany("OilSupplierFile",wherecompany,&supfilemodel) if len(supfilemodel)<1 { _,err = svc.InsertEntityBytbl(""+TmpOilSupplierCertSubName, &companygood) }else { var tmplist1 []suppliercertsub.Tmp_OilSupplierCertSub wherecompany = " Id ="+strconv.Itoa(CertSub.Id) svc.FindFileByCompany("tmp_OilSupplierCertSub",wherecompany,&tmplist1) if len(tmplist1)<1{ wherecompany = " SupplierId ='" + strconv.Itoa(CertSub.SupplierId) + "'" svc.FindFileByCompany("OilSupplierFile", wherecompany, &supfilemodel01) var File01 string for _, Filesub := range supfilemodel01 { File01 = File01 + Filesub.NeedFileType + "," } for _, Filesub := range SurplusList { var supplierModel supplier.OilSupplier svcSupplier := supplier.GetOilSupplierService(utils.DBE) svcSupplier.GetEntityById(strconv.Itoa(CertSub.SupplierId), &supplierModel) //三证合一或五证合一不需要的字段 mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName") File01 = mergerCertSkipField + File01 if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(File01, Filesub.FileName+",") { //三证合一或五证合一了 continue } if strings.Contains(File01, Filesub.FileName+",") { continue } _, err = svc.InsertEntityBytbl(""+TmpOilSupplierCertSubName, &companygood) break } } } } if err == nil { errinfo.Message = "已拉取缺失资质列表!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "拉取列表失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 获取列表新导入的列表 // @Description get user by token // @Success 200 {object} []goodsaptitude.OilGoodsAptitude // @router /importlist [get] func (this *OilBasisBuildController) GetImportEntityList() { //获取分页信息 page := this.GetPageInfoForm() where := " 1=1 " orderby := "Code" asc := true Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = Prop if Order == "asc" { asc = true } else { asc = false } } Code := this.GetString("Code") Name := this.GetString("Name") if Code != "" { where = where + " and Code like '%" + Code + "%'" } if Name != "" { where = where + " and Name like '%" + Name + "%'" } svc := basisbuild.GetOilBasisBuildService(utils.DBE) var list []basisbuild.OilBasisBuild total := svc.GetMyPagingEntitiesWithOrderBytbl(TmpOilBasisBuildName, page.CurrentPage, page.Size, orderby, asc, &list, where) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total datainfo.PageIndex = page.CurrentPage datainfo.ItemsPerPage = page.Size this.Data["json"] = &datainfo this.ServeJSON() } // @Title get 导入excel // @Description get SampleType by token // @Success 200 {object} sampletype.SampleType // @router /importexcel [get] func (this *OilBasisBuildController) 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 := basisbuild.GetOilBasisbuildSession(session) err = svc.TruncateTable(TmpOilBasisBuildName) 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 := svc.GetFCode() Fstrs = "Code,Name," + Fstrs columnArr := strings.Split(Fstrs, ",") defer func() { session.Close() }() codemap := make(map[string]int) for i := 1; i < len(sheet.Rows); i++ { lineNo := strconv.Itoa(i + 1) fmt.Println(lineNo) this.OperationCell(svc, lineNo, columnArr, codemap, 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 *OilBasisBuildController) OperationCell(svc *basisbuild.OilBasisbuildSession, lineNo string, columnArr []string, codemap map[string]int, 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) } } // @Title get 清空导入的信息 // @Description get SampleType by token // @Success 200 {object} sampletype.SampleType // @router /truncateimport [get] func (this *OilBasisBuildController) TruncateImport() { session := utils.DBE.NewSession() err := session.Begin() defer session.Close() svc := basisbuild.GetOilBasisbuildSession(session) err = svc.TruncateTable(TmpOilBasisBuildName) var errorinfo ErrorInfo if err != nil { session.Rollback() errorinfo.Code = -1 errorinfo.Message = "删除失败!" this.Data["json"] = &errorinfo this.ServeJSON() } session.Commit() errorinfo.Code = 0 errorinfo.Message = "删除成功!" this.Data["json"] = &errorinfo this.ServeJSON() } // @Title 将导入的数据 导入到正式表 // @Description get SampleType by token // @Success 200 {object} sampletype.SampleType // @router /insertbasisbuild [get] func (this *OilBasisBuildController) InsertBasisbuild() { session := utils.DBE.NewSession() err := session.Begin() defer session.Close() svc := basisbuild.GetOilBasisbuildSession(session) var errinfo ErrorInfo err = svc.TruncateTable(OilBasisBuildName) if err != nil { session.Rollback() errinfo.Code = -1 errinfo.Message = "跟新失败!" this.Data["json"] = &errinfo this.ServeJSON() } err = svc.InsertBasisBuild(TmpOilBasisBuildName, OilBasisBuildName) if err != nil { session.Rollback() errinfo.Code = -1 errinfo.Message = "跟新失败!" this.Data["json"] = &errinfo this.ServeJSON() } session.Commit() errinfo.Code = 0 errinfo.Message = "跟新成功!" this.Data["json"] = &errinfo this.ServeJSON() } // @Title 更新企业的准入项及资质 // @Description get SampleType by token // @Success 200 {object} sampletype.SampleType // @router /updatasuppiercertsub [get] func (this *OilBasisBuildController) UpdataSuppierCertSub() { t := time.Now() goodsvc := basisbuild.GetOilBasisBuildService(utils.DBE) goodsvc.DeleteTable(TmpOilSupplierCertSubName, "SupplierTypeCode='02'") supsvc := supplier.GetOilSupplierService(utils.DBE) // 所有基建类供应商 var suppliercertList []suppliercert.OilSupplierCert where := "SupplierTypeCode='02' AND OutsideFlog = '' AND (InFlag IN ('1','2')) " supsvc.GetEntities(&suppliercertList, where) var basisbuildList []basisbuild.OilBasisBuild supsvc.GetEntities(&basisbuildList, "") var colsname = []string{"Name"} for _, suppliercert := range suppliercertList { var supplier supplier.OilSupplier wheres := " Id=" + strconv.Itoa(suppliercert.SupplierId) supsvc.GetEntity(&supplier, wheres) log.Println(suppliercert.SupplierId) // 供应商的准入范围 var supplierCertSubList []suppliercertsub.OilSupplierCertSub wheresup := "SupplierId = " + strconv.Itoa(suppliercert.SupplierId) + " and SupplierTypeCode='02' AND Type IN ('1', '3')" supsvc.GetEntities(&supplierCertSubList, wheresup) fmt.Println(len(supplierCertSubList)) mergerCertSkipField := "" if supplier.CredentialFlag == "1" || supplier.CredentialFlag == "2" { paramSvc := baseparameter.GetBaseparameterService(utils.DBE) //三证合一或五证合一不需要的字段 mergerCertSkipField = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName") } for idx := 0; idx < len(supplierCertSubList); idx++ { supplierCertSub := supplierCertSubList[idx] decCode := supplierCertSub.Code // 基建类的准入编码 basisbuildList基建类准入编码 for _, goodsaptitudeClass := range basisbuildList { // 如果编码相同的后 判断有没有改名 然后查询准入项需要哪些资质 去查资质表里有没有这些资质 没有就删除这个准入项 if supplierCertSub.Code == goodsaptitudeClass.Code { decCode = "" // F01 F02...对应的名称 goodsAptitudeNameArr := this.GetBasisBuildName(strconv.Itoa(goodsaptitudeClass.Id)) for _, val := range goodsAptitudeNameArr { if strings.Contains(mergerCertSkipField, val) { break } var supplierFile supplierfile.OilSupplierFile where := "SupplierId=" + strconv.Itoa(suppliercert.SupplierId) + " and NeedFileType='" + val + "'" + " and SupplierTypeCode IN ('000', '02')" has := supsvc.GetEntityByWhere(OilSupplierFileName, where, &supplierFile) if !has { log.Println(supplierCertSub.Code + "====" + val) supsvc.InsertEntityBytbl(TmpOilSupplierCertSubName, supplierCertSub) break } if supplierCertSub.Name != goodsaptitudeClass.Name { var entity suppliercertsub.OilSupplierCertSub entity.Name = goodsaptitudeClass.Name where := "Id = " + strconv.Itoa(supplierCertSub.Id) supsvc.UpdateEntityBywheretbl(OilSupplierCertSubName, &entity, colsname, where) } } break } } if decCode != "" { supsvc.InsertEntityBytbl(TmpOilSupplierCertSubName, supplierCertSub) } } } elapsed := time.Since(t) log.Println(elapsed) var errinfo ErrorInfo errinfo.Code = 0 errinfo.Message = "更新完成!" this.Data["json"] = &errinfo this.ServeJSON() //xlFile.Save(excelFileName) } func (this *OilBasisBuildController) GetBasisBuildName(classId string) []string { var goodsAptitudeName string var goodsAptitudeList []basisbuild.OilBasisBuildF svc := basisbuild.GetOilBasisBuildService(utils.DBE) where := "Id=" + classId svc.GetBasisBuildServiceF(&goodsAptitudeList, where) for _, goodsAptitude := range goodsAptitudeList { t := reflect.TypeOf(goodsAptitude) v := reflect.ValueOf(goodsAptitude) for k := 0; k < t.NumField(); k++ { if v.Field(k).Interface() == "1" { var tableHeader tableheader.BaseTableheader where := "Code='" + t.Field(k).Name + "' and CategoryCode = '02'" has := svc.GetEntityByWhere(BaseTableHeader, where, &tableHeader) if has { goodsAptitudeName += tableHeader.Name + "," } } } } goodsAptitudeName = strings.Trim(goodsAptitudeName, ",") return strings.Split(goodsAptitudeName, ",") } // @Title 导出数据到word,作为导出pdf的中间步骤 // @Description 数据存入word // @Success 200 {object} controllers.Request // @router /exportpdf/:tbid/:typecode [post] func (this *OilBasisBuildController) PdfExport() { Id := this.Ctx.Input.Param(":tbid") SupplierTypeCode := this.Ctx.Input.Param(":typecode") var Url string var fileName string var model1 supplierdataentry.SupplierDataEntry var model2 supplierdataentry.SupplierCertDataEntry svc := supplierdataentry.GetSupplierDataEntryService(utils.DBE) where1 := "1=1" where1 += " AND Id = '" + Id + "'" where2 := "SupplierId = '" + Id + "' and SupplierTypecode='"+ SupplierTypeCode +"'" svc.GetEntityByWhere(OilSupplierName, where1, &model1) svc.GetEntityByWhere(OilSupplierCertName, where2, &model2) var tabledata []supplierdataentry.SupplierCertSubEntry where3:="SupplierId = '" + Id + "' and SupplierTypecode='"+ SupplierTypeCode +"' and Type in ('1','3')"//准入状态的准入项 svc.GetEntitysByOrderbyWhere(TmpOilSupplierCertSubName, where3, "1", &tabledata) datamap := structToMapDemo(model1.OilSupplier) if model2.SupplierTypeCode == "01" { Url = utils.Cfg.MustValue("workflow", "goodsPdfHost") fileName = "待删除物资类准入范围.docx" } else if model2.SupplierTypeCode == "02" { Url = utils.Cfg.MustValue("workflow", "basisPdfHost") fileName = "待删除基建类准入范围.docx" datamap["TJInNotify"] = model1.TJInNotify } else { Url = utils.Cfg.MustValue("workflow", "techPdfHost") fileName = "待删除服务类准入范围.docx" } //model1 datamap["SetupTime"] = model1.SetupTime.Format("2006年01月02日") datamap["QualifCert"] = model1.QualifCert datamap["QualifCertLevel"] = model1.QualifCertLevel datamap["SpecIndustryCert"] = model1.SpecIndustryCert datamap["MaunLicense"] = model1.MaunLicense if model1.HseTraining == "1" { datamap["HseTraining"] = "是" } else { datamap["HseTraining"] = "否" } if model1.OperType != "" { if model1.OperType == "1" || model1.OperType == "制造商"{ datamap["OperType"] = "√制造商 □代理商 □贸易商" }else if model1.OperType == "2" || model1.OperType == "代理商"{ datamap["OperType"] = "□制造商 √代理商 □贸易商" }else if model1.OperType == "3" || model1.OperType == "代理商"{ datamap["OperType"] = "□制造商 □代理商 √贸易商" }else { datamap["OperType"] = "□制造商 □代理商 □贸易商" } } if model1.SpecTypeCode != "" { if model1.SpecTypeCode == "1"{ datamap["SpecTypeCode"] = "√一般外部 □多元企业" }else if model1.SpecTypeCode == "2"{ datamap["SpecTypeCode"] = "□一般外部 √多元企业" }else { datamap["SpecTypeCode"] = "□一般外部 □多元企业" } } if model1.Grade == "1"{ datamap["Grade"] = "一级" }else if model1.SpecTypeCode == "2"{ datamap["Grade"] = "二级" } datamap["Fax"] = model1.Fax datamap["CompanyTel"] = model1.CompanyTel datamap["SupplierName"] = model1.SupplierName datamap["Country"] = model1.Country datamap["MaunAgent"] = model1.MaunAgent datamap["SupplierCertificate"] = model1.SupplierCertificate datamap["MgrUnit"] = model1.MgrUnit datamap["CommercialNo"] = model1.CommercialNo datamap["CountryTaxNo"] = model1.CountryTaxNo datamap["OrganCode"] = model1.OrganCode datamap["Address"] = model1.Address datamap["ZipCode"] = model1.ZipCode datamap["LinkAddress"] = model1.LinkAddress datamap["LinkZipCode"] = model1.LinkZipCode datamap["QualitySystemCert"] = model1.QualitySystemCert datamap["ProductQualityCert"] = model1.ProductQualityCert datamap["MaunLicense"] = model1.MaunLicense datamap["LegalPerson"] = model1.LegalPerson datamap["CompanyType"] = model1.CompanyType datamap["ContactName"] = model1.ContactName datamap["RegCapital"] = strconv.FormatFloat(model1.RegCapital,'f',2,64)+"万元"+model1.Currency datamap["DepositBank"] = model1.DepositBank datamap["BankAccount"] = model1.BankAccount datamap["Mobile"] = model1.Mobile datamap["EMail"] = model1.EMail datamap["BankCreditRating"] = model1.BankCreditRating datamap["BusinessScope"] = model1.BusinessScope datamap["Telphone"] = model1.Telphone datamap["AccessCardNo"] = model2.AccessCardNo datamap["PrintYear"] = time.Now().Year() datamap["PrintMonth"] = time.Now().Month() datamap["PrintDay"] = time.Now().Day() datamap["Name"] = "" if len(tabledata) != 0 { var Name string Name = "\n待删除准入范围:"+ tabledata[0].Code Name = Name + " " + tabledata[0].Name var i int for i = 1; i < len(tabledata); i++ { Name += ";" Name += tabledata[i].Code Name = Name + " " + tabledata[i].Name } //if i == 100 { // Name += "(准入范围未完全显示,请到系统查看详情)" //} datamap["Name"] =datamap["Name"].(string) + Name } else { datamap["Name"] =datamap["Name"].(string) } svcActiviti := workflow.GetActivitiService(utils.DBE) retDocUrl := svcActiviti.FillWordTemplate(datamap, Url, fileName) var datainfo ErrorDataInfo datainfo.Code = 0 datainfo.Item = retDocUrl datainfo.Message = "准备导出" this.Data["json"] = &datainfo this.ServeJSON() }