| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989 |
- package oilsupplier
- import (
- "dashoo.cn/backend/api/business/oilsupplier/supplier"
- "dashoo.cn/backend/api/business/oilsupplier/suppliercert"
- "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
- "dashoo.cn/backend/api/business/oilsupplier/supplierfile"
- "dashoo.cn/backend/api/business/oilsupplier/tableheader"
- "encoding/json"
- "fmt"
- "github.com/tealeg/xlsx"
- "log"
- "os"
- "reflect"
- "strconv"
- "strings"
- "time"
- "dashoo.cn/backend/api/business/oilsupplier/goodsaptitudeclass"
- "dashoo.cn/backend/api/business/items"
- "dashoo.cn/backend/api/business/baseUser"
- "dashoo.cn/backend/api/business/oilsupplier/goodsaptitude"
- . "dashoo.cn/backend/api/controllers"
- "dashoo.cn/business2/userRole"
- "dashoo.cn/business2/parameter"
- "dashoo.cn/utils"
- . "github.com/linxGnu/goseaweedfs"
- )
- type OilGoodsAptitudeController struct {
- BaseController
- }
- // @Title 获取列表
- // @Description get user by token
- // @Success 200 {object} []goodsaptitude.OilGoodsAptitude
- // @router /list [get]
- func (this *OilGoodsAptitudeController) 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
- }
- }
- Edition := this.GetString("Edition")
- CreateOn := this.GetString("CreateOn")
- Code := this.GetString("Code")
- Name := this.GetString("Name")
- BigClassName := this.GetString("BigClassName")
- BigClassCode := this.GetString("BigClassCode")
- MiddleClassName := this.GetString("MiddleClassName")
- SmallClassName := this.GetString("SmallClassName")
- GoodsName := this.GetString("GoodsName")
- GoodsLevel := this.GetString("GoodsLevel")
- GoodsDesc := this.GetString("GoodsDesc")
- Standard := this.GetString("Standard")
- CompanyType := this.GetString("CompanyType")
- if Edition != "" {
- where = where + " and Edition = '" + Edition + "'"
- }
- if Code != "" {
- where = where + " and Code like '%" + Code + "%'"
- }
- if Name != "" {
- where = where + " and Name like '%" + Name + "%'"
- }
- if BigClassName != "" {
- where = where + " and Name1 like '%" + BigClassName + "%'"
- }
- if BigClassCode != "" {
- where = where + " and Code1 like '%" + BigClassCode + "%'"
- }
- if MiddleClassName != "" {
- where = where + " and Name2 like '%" + MiddleClassName + "%'"
- }
- if SmallClassName != "" {
- where = where + " and Name3 like '%" + SmallClassName + "%'"
- }
- if GoodsName != "" {
- where = where + " and Name4 like '%" + GoodsName + "%'"
- }
- if GoodsLevel != "" {
- where = where + " and GoodsLevel like '%" + GoodsLevel + "%'"
- }
- if GoodsDesc != "" {
- where = where + " and GoodsDesc like '%" + GoodsDesc + "%'"
- }
- if Standard != "" {
- where = where + " and Standard '%" + Standard + "%'"
- }
- if CompanyType != "" {
- where = where + " and CompanyType '%" + CompanyType + "%'"
- }
- 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 := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- var list []goodsaptitude.OilGoodsAptitudeView
- total := svc.GetMyPagingEntitiesWithOrderBytbl(OilGoodsAptDetailViewName, 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} []goodsaptitude.OilGoodsAptitude
- // @router /importlist [get]
- func (this *OilGoodsAptitudeController) 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
- }
- }
- Edition := this.GetString("Edition")
- CreateOn := this.GetString("CreateOn")
- Code := this.GetString("Code")
- Name := this.GetString("Name")
- BigClassName := this.GetString("BigClassName")
- BigClassCode := this.GetString("BigClassCode")
- MiddleClassName := this.GetString("MiddleClassName")
- SmallClassName := this.GetString("SmallClassName")
- GoodsName := this.GetString("GoodsName")
- GoodsLevel := this.GetString("GoodsLevel")
- GoodsDesc := this.GetString("GoodsDesc")
- Standard := this.GetString("Standard")
- CompanyType := this.GetString("CompanyType")
- if Edition != "" {
- where = where + " and Edition = '" + Edition + "'"
- }
- if Code != "" {
- where = where + " and Code like '%" + Code + "%'"
- }
- if Name != "" {
- where = where + " and Name like '%" + Name + "%'"
- }
- if BigClassName != "" {
- where = where + " and Name1 like '%" + BigClassName + "%'"
- }
- if BigClassCode != "" {
- where = where + " and Code1 like '%" + BigClassCode + "%'"
- }
- if MiddleClassName != "" {
- where = where + " and Name2 like '%" + MiddleClassName + "%'"
- }
- if SmallClassName != "" {
- where = where + " and Name3 like '%" + SmallClassName + "%'"
- }
- if GoodsName != "" {
- where = where + " and Name4 like '%" + GoodsName + "%'"
- }
- if GoodsLevel != "" {
- where = where + " and GoodsLevel like '%" + GoodsLevel + "%'"
- }
- if GoodsDesc != "" {
- where = where + " and GoodsDesc like '%" + GoodsDesc + "%'"
- }
- if Standard != "" {
- where = where + " and Standard '%" + Standard + "%'"
- }
- if CompanyType != "" {
- where = where + " and CompanyType '%" + CompanyType + "%'"
- }
- 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 := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- var list []goodsaptitude.OilGoodsAptitudeView
- total := svc.GetMyPagingEntitiesWithOrderBytbl(ImportOilGoodsAptDetailViewName, 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 获取列表2019版本
- // @Description
- // @Success 200 {object}
- // @router /list_2019 [get]
- func (this *OilGoodsAptitudeController) GetEntityList_2019() {
- //获取分页信息
- 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
- }
- }
- Edition := this.GetString("Edition")
- Code := this.GetString("Code")
- Name := this.GetString("Name")
- if Edition != "" {
- where = where + " and a.Edition = '" + Edition + "'"
- }
- if Code != "" {
- where = where + " and b.Code like '%" + Code + "%'"
- }
- if Name != "" {
- where = where + " and b.Name like '%" + Name + "%'"
- }
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- var list []goodsaptitude.OilGoodsAptitude_2
- total := svc.GetList_2019(OilGoodsAptitudeName, OilGoodsAptitudeClassName, 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 *OilGoodsAptitudeController) 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} goodsaptitude.OilGoodsAptitude
- // @router /get/:id [get]
- func (this *OilGoodsAptitudeController) GetEntity() {
- Id := this.Ctx.Input.Param(":id")
- var model goodsaptitude.OilGoodsAptitudeView
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- //svc.GetEntityByIdBytbl(""+OilGoodsAptitudeName, Id, &model)
- where := " Id =" + Id
- svc.GetEntityByWhere(OilGoodsAptDetailViewName, where, &model)
- this.Data["json"] = &model
- this.ServeJSON()
- }
- // @Title 获取实体
- // @Description 获取实体
- // @Success 200 {object}
- // @router /get_2019/:id [get]
- func (this *OilGoodsAptitudeController) GetEntity_2019() {
- Id := this.Ctx.Input.Param(":id")
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- var tempMap []map[string]string
- sql := `select a.Id,a.ClassId,a.F01,a.F02,a.F03,a.F04,a.F05,a.F06,a.F07,a.F08,a.F09,a.F10,
- a.F11,a.F12,a.F13,a.F14,a.F15,a.F16,a.F17,a.F18,a.F19,a.F20,
- a.F21,a.F22,a.F23,a.F24,a.F25,a.F26,a.F27,a.F28,a.F29,a.F30,
- a.F31,a.F32,a.F33,a.F34,a.F35,a.F36,a.F37,a.F38,a.F39,a.F40,
- a.F41,a.F42,a.F43,a.F44,a.F45,a.F46,b.Code, b.Name `
- sql += ` from ` + OilGoodsAptitudeName + ` a `
- sql += ` left join ` + OilGoodsAptitudeClassName + " b on b.Id = a.ClassId"
- sql += ` where a.Id='` + Id + `'`
- tempMap, _ = svc.DBE.QueryString(sql)
- this.Data["json"] = &tempMap
- this.ServeJSON()
- }
- // @Title 添加
- // @Description 新增
- // @Success 200 {object} controllers.Request
- // @router /add/:id [post]
- func (this *OilGoodsAptitudeController) AddEntity() {
- classId := this.Ctx.Input.Param(":id")
- var model goodsaptitude.OilGoodsAptitude
- var jsonBlob = this.Ctx.Input.RequestBody
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- json.Unmarshal(jsonBlob, &model)
- model.CreateOn = time.Now()
- model.CreateBy = this.User.Realname
- model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- model.ClassId, _ = strconv.Atoi(classId)
- //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
- _, err := svc.InsertEntityBytbl(""+OilGoodsAptitudeName, &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 /add_2019 [post]
- func (this *OilGoodsAptitudeController) AddEntity_2019() {
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- var model goodsaptitudeclass.OilGoodsAptitudeClass
- var jsonBlob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonBlob, &model)
- model.ParentId = -1
- model.Edition = "2"
- model.CreateOn = time.Now()
- model.CreateBy = this.User.Realname
- model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- _, err := svc.InsertEntityBytbl(""+OilGoodsAptitudeClassName, &model)
- var model2 goodsaptitude.OilGoodsAptitude
- json.Unmarshal(jsonBlob, &model2)
- model2.ClassId = model.Id
- model2.Edition = "2"
- model2.CreateOn = time.Now()
- model2.CreateBy = this.User.Realname
- model2.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- _, err = svc.InsertEntityBytbl(""+OilGoodsAptitudeName, &model2)
- var errinfo ErrorDataInfo
- if err == nil {
- //新增
- errinfo.Message = "添加成功!"
- errinfo.Code = 0
- errinfo.Item = model2.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 *OilGoodsAptitudeController) 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 goodsaptitude.OilGoodsAptitude
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- var jsonBlob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonBlob, &model)
- model.ModifiedOn = time.Now()
- model.ModifiedBy = this.User.Realname
- model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- cols := []string{
- "Id",
- "Code",
- "Name",
- "BigClassName",
- "MiddleClassName",
- "SmallClassName",
- "GoodsName",
- "GoodsLevel",
- "GoodsDesc",
- "Standard",
- "CompanyType",
- "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",
- "F26",
- "F27",
- "F28",
- "F29",
- "F30",
- "F31",
- "F32",
- "F33",
- "F34",
- "F35",
- "F36",
- "F37",
- "F38",
- "F39",
- "F40",
- "F41",
- "F42",
- "F43",
- "F44",
- "F45",
- "F46",
- "Remark",
- "DeletionStateCode",
- "CreateOn",
- "CreateUserId",
- "CreateBy",
- "ModifiedOn",
- "ModifiedUserId",
- "ModifiedBy",
- }
- err := svc.UpdateEntityBytbl(""+OilGoodsAptitudeName, 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} controllers.Request
- // @router /update_2019/:id [post]
- func (this *OilGoodsAptitudeController) UpdateEntity_2019() {
- id := this.Ctx.Input.Param(":id")
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var model goodsaptitude.OilGoodsAptitude
- var jsonBlob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonBlob, &model)
- model.ModifiedOn = time.Now()
- model.ModifiedBy = this.User.Realname
- model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- cols := []string{
- "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",
- "F26",
- "F27",
- "F28",
- "F29",
- "F30",
- "F31",
- "F32",
- "F33",
- "F34",
- "F35",
- "F36",
- "F37",
- "F38",
- "F39",
- "F40",
- "F41",
- "F42",
- "F43",
- "F44",
- "F45",
- "F46",
- "ModifiedOn",
- "ModifiedUserId",
- "ModifiedBy",
- }
- err := svc.UpdateEntityBytbl(""+OilGoodsAptitudeName, id, &model, cols)
- var model2 goodsaptitudeclass.OilGoodsAptitudeClass
- json.Unmarshal(jsonBlob, &model2)
- model2.ModifiedOn = time.Now()
- model2.ModifiedBy = this.User.Realname
- model2.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- cols2 := []string{
- "Code",
- "Name",
- "ModifiedOn",
- "ModifiedUserId",
- "ModifiedBy",
- }
- err = svc.UpdateEntityBytbl(""+OilGoodsAptitudeClassName, model.ClassId, &model2, cols2)
- 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} controllers.Request
- // @router /updatecode/:id [post]
- func (this *OilGoodsAptitudeController) UpdateCodeEntity() {
- var errinfo ErrorInfo
- var err error
- id := this.Ctx.Input.Param(":id")
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var classall goodsaptitude.OilGoodsAptitudeClassView
- var model goodsaptitudeclass.OilGoodsAptitudeClass
- var classmodel []goodsaptitudeclass.OilGoodsAptitudeClass
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- var jsonBlob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonBlob, &classall)
- model.ModifiedOn = time.Now()
- model.ModifiedBy = this.User.Realname
- model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- colsName := []string{"Name"}
- colsCode := []string{"Code"}
- //svc.GetEntityById(id, &model)
- if classall.Name1 != "" {
- where := " Name = '" + classall.Name1 + "' and Id <> " + utils.ToStr(classall.Id1)
- svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
- if len(classmodel) > 0 {
- errinfo.Message = "大类名称已存在,请重新添加!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- } else {
- model.Name = classall.Name1
- err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id1, &model, colsName)
- }
- }
- if classall.Name2 != "" {
- where := " Name = '" + classall.Name2 + "' and Id <> " + utils.ToStr(classall.Id2)
- svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
- if len(classmodel) > 0 {
- errinfo.Message = "中类名称已存在,请重新添加!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- } else {
- model.Name = classall.Name2
- err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id2, &model, colsName)
- }
- }
- if classall.Name3 != "" {
- where := " Name = '" + classall.Name3 + "' and Id <> " + utils.ToStr(classall.Id3)
- svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
- if len(classmodel) > 0 {
- errinfo.Message = "小类名称已存在,请重新添加!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- } else {
- model.Name = classall.Name3
- err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id3, &model, colsName)
- }
- }
- if classall.Name4 != "" {
- where := " Name = '" + classall.Name4 + "' and Id <> " + utils.ToStr(classall.Id4)
- svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
- if len(classmodel) > 0 {
- errinfo.Message = "品名已存在,请重新添加!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- } else {
- model.Name = classall.Name4
- err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id4, &model, colsName)
- }
- }
- if classall.Code1 != "" {
- where := " Code = " + classall.Code1 + " and Id <> " + utils.ToStr(classall.Id1)
- svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
- if len(classmodel) > 0 {
- errinfo.Message = "大类编码已存在,请重新添加!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- } else {
- model.Code = classall.Code1
- err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id1, &model, colsCode)
- }
- }
- if classall.Code2 != "" {
- where := " Code = " + classall.Code2 + " and Id <> " + utils.ToStr(classall.Id2)
- svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
- if len(classmodel) > 0 {
- errinfo.Message = "中类编码已存在,请重新添加!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- } else {
- model.Code = classall.Code2
- err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id2, &model, colsCode)
- }
- }
- if classall.Code3 != "" {
- where := " Code = " + classall.Code3 + " and Id <> " + utils.ToStr(classall.Id3)
- svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
- if len(classmodel) > 0 {
- errinfo.Message = "小类编码已存在,请重新添加!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- } else {
- model.Code = classall.Code3
- err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id3, &model, colsCode)
- }
- }
- if classall.Code4 != "" {
- where := " Code = " + classall.Code4 + " and Id <> " + utils.ToStr(classall.Id4)
- svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
- if len(classmodel) > 0 {
- errinfo.Message = "品名编码已存在,请重新添加!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- } else {
- model.Code = classall.Code4
- err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id4, &model, colsCode)
- }
- }
- 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 *OilGoodsAptitudeController) 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 goodsaptitude.OilGoodsAptitude
- var entityempty goodsaptitude.OilGoodsAptitude
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- opdesc := "删除-" + Id
- err := svc.DeleteOperationAndWriteLogBytbl(""+OilGoodsAptitudeName, 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 get 查询
- // @Description get SampleType by token
- // @Success 200 {object} sampletype.SampleType
- // @router /goodsparentlist/:name [get]
- func (this *OilGoodsAptitudeController) GoodsParentList() {
- Name := this.Ctx.Input.Param(":name")
- if Name != "" {
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- where1 := "1=1"
- where1 += " AND Name LIKE '%" + Name + "%' OR Code LIKE '" + Name + "%' "
- sqlStr := "SELECT Id, Code, Name, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass " +
- "WHERE " + where1 + " AND Edition='1' AND DeletionStateCode = 0 ORDER BY Code"
- list, _ := svc.DBE.QueryString(sqlStr)
- /*
- sql := "SELECT Id, Code, Name, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass " +
- "WHERE DeletionStateCode = 0 AND " + where1 + " OR Id = (" + sqlStr + ")" +" ORDER BY Code"
- list, _ := svc.DBE.QueryString(sql)*/
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- }
- // @Title get 获取子类
- // @Description get SampleType by token
- // @Success 200 {object} sampletype.SampleType
- // @router /goodschildlist/:id [get]
- func (this *OilGoodsAptitudeController) GoodsChildList() {
- ParentId := this.Ctx.Input.Param(":id")
- sqlStr := "SELECT Id, `Code`, `Name`, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass WHERE FIND_IN_SET(ParentId, fun_getOilGoodsAptitudeClasschildlist(" + ParentId + ")) AND DeletionStateCode = 0 order by Code"
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- list, _ := svc.DBE.QueryString(sqlStr)
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title get 获取子类
- // @Description get SampleType by token
- // @Success 200 {object} sampletype.SampleType
- // @router /goodschildlistbypid/:parentid [get]
- func (this *OilGoodsAptitudeController) GoodsChildLisByParentId() {
- ParentId := this.Ctx.Input.Param(":parentid")
- sqlStr := "SELECT o.Id, o.`Code`, o.`Name`, concat(o.Code, ' ', o.Name) as CodeName, o.ParentId, g.GoodsLevel," +
- " (CASE WHEN length(Code)>=8 THEN '1' ELSE '0' END) as Leaf FROM OilGoodsAptitudeClass o " +
- " LEFT JOIN `OilGoodsAptitude` g ON (g.ClassId = o.Id)" +
- " WHERE o.ParentId = '" + ParentId + "' AND o.Edition='1' AND o.DeletionStateCode = 0 order by o.Code"
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- list, _ := svc.DBE.QueryString(sqlStr)
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title get 导出ex
- // @Description get SampleType by token
- // @Success 200 {object} sampletype.SampleType
- // @router /exportexcelall [get]
- func (this *OilGoodsAptitudeController) ExportExcelAll() {
- //获取分页信息
- //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
- }
- }
- Edition := this.GetString("Edition")
- if Edition != "" {
- where = where + " and Edition = '" + Edition + "'"
- }
- t := time.Now()
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- var list []goodsaptitude.OilGoodsAptitudeView
- svc.GetMyPagingEntitiesWithOrderBytbl(OilGoodsAptDetailViewName, 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)
- //rowhead := sheet.AddRow()
- //rowhead.WriteSlice(&title, -1)
- cellname := strings.Split(showcolumnarr, ",")
- row := sheet.AddRow()
- row.WriteSlice(&cellname, -1)
- for _, item := range list {
- var enumModel goodsaptitude.OilGoodsAptitudeView
- 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
- }
- //this.SaveSampleXlsx(filetitle, title, showcolumnarr, list, f)
- 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 get 导出ex
- // @Description get SampleType by token
- // @Success 200 {object} sampletype.SampleType
- // @router /exportexcelall2019 [get]
- func (this *OilGoodsAptitudeController) ExportExcelAll2019() {
- //获取分页信息
- //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
- }
- }
- Edition := this.GetString("Edition")
- if Edition != "" {
- where = where + " and a.Edition = '" + Edition + "'"
- }
- t := time.Now()
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- var list []goodsaptitude.OilGoodsAptitude_2
- svc.GetList_2019(OilGoodsAptitudeName, OilGoodsAptitudeClassName, 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 goodsaptitude.OilGoodsAptitude_2
- 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 get 导入excel
- // @Description get SampleType by token
- // @Success 200 {object} sampletype.SampleType
- // @router /importexcel [get]
- func (this *OilGoodsAptitudeController) 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 := goodsaptitude.GetOilGoodsAptitudeSession(session)
- err = svc.TruncateTable(Tmp_OilGoodsAptitudeName)
- if err != nil {
- session.Rollback()
- errorinfo.Code = -2
- errorinfo.Message = "导入失败!"
- this.Data["json"] = &errorinfo
- this.ServeJSON()
- }
- err = svc.TruncateTable(Tmp_OilGoodsAptitudeClassName)
- if err != nil {
- session.Rollback()
- errorinfo.Code = -2
- errorinfo.Message = "导入失败!"
- this.Data["json"] = &errorinfo
- this.ServeJSON()
- }
- _dir := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx"
- utils.DownloadFile(url, "temp.xlsx", _dir)
- t := time.Now()
- filePath := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx/temp.xlsx"
- 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 = "GoodsLevel,GoodsDesc,Standard,CompanyType," + Fstrs
- columnArr := strings.Split(Fstrs, ",")
- defer func() {
- session.Close()
- }()
- codemap := make(map[string]int)
- for i := 3; i < len(sheet.Rows); i++ {
- lineNo := strconv.Itoa(i + 1)
- 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 *OilGoodsAptitudeController) OperationCell(svc *goodsaptitude.OilGoodsAptitudeSession, 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 + ","
- }
- }()
- parentId := 0
- classId := 0
- cellsArrLen := len(cellsArr)
- cellD := strings.TrimSpace(cellsArr[3].String())
- var valstr = ""
- for idx, cell := range cellsArr {
- if idx < 4 {
- cellstr := cell.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 idx != 0 {
- upcellstr := cellsArr[idx -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 := svc.InsertEntityBytbl(Tmp_OilGoodsAptitudeClassName, &entity)
- if err != nil {
- panic(err)
- break
- }
- classId = entity.Id
- if idx != 3 {
- codemap[cellArr[0]] = entity.Id
- }
- }
- }
- if idx >= 4 {
- valstr += "'" + cellsArr[idx].String() + "',"
- }
- }
- if cellD != "" {
- valstr = strings.Trim(valstr, ",")
- valstr = strings.Replace(valstr, "是", "1", -1)
- log.Println(cellsArr[3].String() + "==" + valstr)
- var columnstr = ""
- for l := 0; l < cellsArrLen - 4; l++ {
- columnstr += columnArr[l] + ","
- }
- columnstr = strings.Trim(columnstr, ",")
- err := svc.InsertTmpGoodsAptitude(strconv.Itoa(classId), columnstr, valstr)
- if err != nil {
- panic(err)
- }
- }
- }
- // @Title get 清空导入的信息
- // @Description get SampleType by token
- // @Success 200 {object} sampletype.SampleType
- // @router /truncateimport [get]
- func (this *OilGoodsAptitudeController) TruncateImport() {
- session := utils.DBE.NewSession()
- err := session.Begin()
- defer session.Close()
- svc := goodsaptitude.GetOilGoodsAptitudeSession(session)
- err = svc.TruncateTable(Tmp_OilGoodsAptitudeName)
- var errorinfo ErrorInfo
- if err != nil{
- session.Rollback()
- errorinfo.Code = -1
- errorinfo.Message = "删除失败!"
- this.Data["json"] = &errorinfo
- this.ServeJSON()
- }
- err = svc.TruncateTable(Tmp_OilGoodsAptitudeClassName)
- 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 /insertgoodsaptitude [get]
- func (this *OilGoodsAptitudeController) InsertGoodsAptitude() {
- session := utils.DBE.NewSession()
- err := session.Begin()
- defer session.Close()
- svc := goodsaptitude.GetOilGoodsAptitudeSession(session)
- err = svc.InsertGoodsAptitude(Tmp_OilGoodsAptitudeName, OilGoodsAptitudeName)
- var errinfo ErrorInfo
- if err != nil {
- session.Rollback()
- errinfo.Code = -1
- errinfo.Message = "跟新失败!"
- this.Data["josn"] = &errinfo
- this.ServeJSON()
- }
- err = svc.InsertGoodsAptitude(Tmp_OilGoodsAptitudeClassName, OilGoodsAptitudeClassName)
- 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 *OilGoodsAptitudeController) UpdataSuppierCertSub() {
- //excelFileName := "F:/ssa.xlsx"
- //xlFile, _ := xlsx.OpenFile(excelFileName)
- //var sheet = xlFile.Sheets[0]
- t := time.Now()
- goodsvc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- goodsvc.TruncateTable(TmpOilSupplierCertSubName)
- supsvc := supplier.GetOilSupplierService(utils.DBE)
- var suppliercertList []suppliercert.OilSupplierCert
- where := "SupplierTypeCode='01' AND OutsideFlog = '' AND (InFlag IN ('1','2')) "
- supsvc.GetEntities(&suppliercertList, where)
- var goodsaptitudeClassList []goodsaptitudeclass.OilGoodsAptitudeClass
- whereclass := "LENGTH(CODE) = 8 "
- supsvc.GetEntities(&goodsaptitudeClassList, whereclass)
- var colsname = []string{"Name"}
- var colsLevel = []string{"GoodsLevel"}
- for _, suppliercert := range suppliercertList {
- //row := sheet.AddRow()
- //cell := row.AddCell()
- //cell.Value = strconv.Itoa(suppliercert.SupplierId)
- log.Println(suppliercert.SupplierId)
- var supplierCertSubList []suppliercertsub.OilSupplierCertSub
- wheresup := "SupplierId = " + strconv.Itoa(suppliercert.SupplierId) + " and SupplierTypeCode='01' AND Type IN ('1', '3')"
- supsvc.GetEntities(&supplierCertSubList, wheresup)
- fmt.Println(len(supplierCertSubList))
- // 准入项
- //for idx, supplierCertSub := range supplierCertSubList {
- for idx :=0; idx < len(supplierCertSubList); idx++{
- //row := sheet.AddRow()
- //cell := row.AddCell()
- //cell.Value = "删除"
- supplierCertSub := supplierCertSubList[idx]
- decCode := supplierCertSub.Code
- // 物资类的准入编码
- for _, goodsaptitudeClass := range goodsaptitudeClassList {
- // 如果编码相同的后 判断有没有改名 然后查询准入项需要哪些资质 去查资质表里有没有这些资质 没有就删除这个准入项
- if supplierCertSub.Code == goodsaptitudeClass.Code {
- decCode = ""
- goodsAptitudeNameArr := this.GetGoodsAptitudeName(strconv.Itoa(goodsaptitudeClass.Id), strconv.Itoa(supplierCertSub.IsManufacturer))
- for _, val := range goodsAptitudeNameArr {
- var supplierFile supplierfile.OilSupplierFile
- where := "SupplierId=" + strconv.Itoa(suppliercert.SupplierId) + " and NeedFileType='" + val + "'" + " and SupplierTypeCode IN ('000', '01')"
- has := supsvc.GetEntityByWhere(OilSupplierFileName, where, &supplierFile)
- if !has {
- //cell := row.AddCell()
- //cell.Value = supplierCertSub.Code + " " + supplierCertSub.Name
- log.Println(supplierCertSub.Code + "====" + val)
- //wheredel := "Id = " + strconv.Itoa(supplierCertSub.Id)
- //supsvc.DeleteEntityBytbl(OilSupplierCertSubName, wheredel)
- supsvc.InsertEntityBytbl(TmpOilSupplierCertSubName, supplierCertSub)
- break
- }
- if supplierCertSub.Name != goodsaptitudeClass.Name {
- //row := sheet.AddRow()
- //cell := row.AddCell()
- //cell.Value = supplierCertSub.Code + ":" + supplierCertSub.Name + "==" + goodsaptitudeClass.Name
- var entity suppliercertsub.OilSupplierCertSub
- entity.Name = goodsaptitudeClass.Name
- where := "Id = " + strconv.Itoa(supplierCertSub.Id)
- supsvc.UpdateEntityBywheretbl(OilSupplierCertSubName, &entity, colsname, where)
- }
- var goodsAptitude goodsaptitude.OilGoodsAptitude
- whereg := "ClassId = " + strconv.Itoa(goodsaptitudeClass.Id)
- supsvc.GetEntity(goodsAptitude, whereg)
- if goodsAptitude.GoodsLevel != supplierCertSub.GoodsLevel {
- var entity suppliercertsub.OilSupplierCertSub
- entity.GoodsLevel = goodsAptitude.GoodsLevel
- where := "Id = " + strconv.Itoa(supplierCertSub.Id)
- supsvc.UpdateEntityBywheretbl(OilSupplierCertSubName, &entity, colsLevel, where)
- }
- }
- break
- }
- }
- if decCode != "" {
- //wheredel := "Code = '" + decCode + "'"
- //supsvc.DeleteEntityBytbl(OilSupplierCertSubName, wheredel)
- supsvc.InsertEntityBytbl(TmpOilSupplierCertSubName, supplierCertSub)
- }
- //cell1 := row.AddCell()
- //cell1.Value = decCode
- }
- }
- 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 *OilGoodsAptitudeController) GetGoodsAptitudeName(classId, IsManuf string) []string {
- var goodsAptitudeName string
- var goodsAptitudeList []goodsaptitude.OilGoodsAptitudeF
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- where := "ClassId=" + classId
- svc.GetGoodsAptitudeF(&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 IsManuf in ('0','" + IsManuf + "')"
- has := svc.GetEntityByWhere(BaseTableHeader, where, &tableHeader)
- if has {
- goodsAptitudeName += tableHeader.Name + ","
- }
- }
- }
- }
- return strings.Split(goodsAptitudeName, ",")
- }
- // @Title 获取所有
- // @Description
- // @Success 200 {object}
- // @router /getcompanylist [post]
- func (this *OilGoodsAptitudeController) 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 = '01' 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 /delcertsublist [get]
- func (this *OilGoodsAptitudeController) GetDelCertSubList() {
- //获取分页信息
- page := this.GetPageInfoForm()
- where := " 1=1 "
- orderby := "Id"
- asc := false
- Order := this.GetString("Order")
- Prop := this.GetString("Prop")
- if Order != "" && Prop != "" {
- orderby = Prop
- if Order == "asc" {
- asc = true
- }
- }
- Id := this.GetString("Id")
- SupplierId := this.GetString("SupplierId")
- SupplierCertId := this.GetString("SupplierCertId")
- SupplierTypeCode := this.GetString("SupplierTypeCode")
- Code := this.GetString("Code")
- Name := this.GetString("Name")
- Remark := this.GetString("Remark")
- IsDelete := this.GetString("IsDelete")
- CreateOn := this.GetString("CreateOn")
- CreateUserId := this.GetString("CreateUserId")
- CreateBy := this.GetString("CreateBy")
- ModifiedOn := this.GetString("ModifiedOn")
- ModifiedUserId := this.GetString("ModifiedUserId")
- ModifiedBy := this.GetString("ModifiedBy")
- if Id != "" {
- where = where + " and Id like '%" + Id + "%'"
- }
- if SupplierId != "" {
- where = where + " and SupplierId like '%" + SupplierId + "%'"
- }
- if SupplierCertId != "" {
- where = where + " and SupplierCertId = '" + SupplierCertId + "'"
- }
- if SupplierTypeCode != "" {
- where = where + " and SupplierTypeCode = '" + SupplierTypeCode + "'"
- }
- if Code != "" {
- where = where + " and Code like '%" + Code + "%'"
- }
- if Name != "" {
- where = where + " and Name like '%" + Name + "%'"
- }
- if Remark != "" {
- where = where + " and Remark like '%" + Remark + "%'"
- }
- if IsDelete != "" {
- where = where + " and IsDelete like '%" + IsDelete + "%'"
- }
- if CreateUserId != "" {
- where = where + " and CreateUserId like '%" + CreateUserId + "%'"
- }
- if CreateBy != "" {
- where = where + " and CreateBy like '%" + CreateBy + "%'"
- }
- if ModifiedOn != "" {
- where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
- }
- if ModifiedUserId != "" {
- where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
- }
- if ModifiedBy != "" {
- where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
- }
- if CreateOn != "" {
- dates := strings.Split(CreateOn, ",")
- if len(dates) == 2 {
- minDate := dates[0]
- maxDate := dates[1]
- where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
- }
- }
- where = where + " and Type in (1, 3)"
- svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
- var list []suppliercertsub.Tmp_OilSupplierCertSub
- total := svc.GetMyPagingEntitiesWithOrderBytbl(TmpOilSupplierCertSubName, 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} []suppliercertsub.OilSupplierCertSub
- // @router /deltmpsuppliercertsub [get]
- func (this *OilGoodsAptitudeController) DelTmpSupplierCertSub() {
- var err error
- session := utils.DBE.NewSession()
- session.Begin()
- defer session.Close()
- svc := goodsaptitude.GetOilGoodsAptitudeSession(session)
- var supplierCertSubList []suppliercertsub.Tmp_OilSupplierCertSub
- wheredel := "1=1 and SupplierTypeCode = '01'"
- 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 *OilGoodsAptitudeController) FindInconformity() {
- var errinfo ErrorInfo
- var err error
- var model goodsaptitude.OilGoodsAptitude_2
- var companygoodslist []suppliercertsub.OilSupplierCertSub
- var companygood suppliercertsub.OilSupplierCertSub
- var SurplusList1 []supplierfile.FileList
- var SurplusList2 []supplierfile.FileList
- var supfilemodel []supplierfile.OilSupplierFile
- var supfilemodel01 []supplierfile.OilSupplierFile
- var supfilemodel02 []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 = '01'"
- svc.FindGoodsByCode("OilSupplierCertSub",where,&companygoodslist)
- SurplusList1 = filesvc.GetGoodsNeedFileList(strconv.Itoa(model.ClassId), "1")
- SurplusList2 = filesvc.GetGoodsNeedFileList(strconv.Itoa(model.ClassId), "2")
- 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) + "' and IsManuf in ('0','1')"
- svc.FindFileByCompany("OilSupplierFile", wherecompany, &supfilemodel01)
- var File01 string
- for _, Filesub := range supfilemodel01 {
- File01 = File01 + Filesub.NeedFileType + ","
- }
- for _, Filesub := range SurplusList1 {
- 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
- }
- }
- var tmplist2 []suppliercertsub.Tmp_OilSupplierCertSub
- wherecompany = " Id ="+strconv.Itoa(CertSub.Id)
- svc.FindFileByCompany("tmp_OilSupplierCertSub",wherecompany,&tmplist2)
- if len(tmplist2)<1{
- wherecompany = " SupplierId ='" + strconv.Itoa(CertSub.SupplierId) + "' and IsManuf in ('0','2')"
- svc.FindFileByCompany("OilSupplierFile", wherecompany, &supfilemodel02)
- var File02 string
- for _, Filesub := range supfilemodel02 {
- File02 = File02 + Filesub.NeedFileType + ","
- }
- for _, Filesub := range SurplusList2 {
- var supplierModel supplier.OilSupplier
- svcSupplier := supplier.GetOilSupplierService(utils.DBE)
- svcSupplier.GetEntityById(strconv.Itoa(CertSub.SupplierId), &supplierModel)
- //三证合一或五证合一不需要的字段
- mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
- File02 = mergerCertSkipField + File02
- if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(File02, Filesub.FileName+",") { //三证合一或五证合一了
- continue
- }
- if strings.Contains(File02, 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()
- }
- }
|