goodsaptitude.go 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994
  1. package oilsupplier
  2. import (
  3. "dashoo.cn/backend/api/business/oilsupplier/supplier"
  4. "dashoo.cn/backend/api/business/oilsupplier/suppliercert"
  5. "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
  6. "dashoo.cn/backend/api/business/oilsupplier/supplierfile"
  7. "dashoo.cn/backend/api/business/oilsupplier/tableheader"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/tealeg/xlsx"
  11. "log"
  12. "os"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "time"
  17. "dashoo.cn/backend/api/business/oilsupplier/goodsaptitudeclass"
  18. "dashoo.cn/backend/api/business/items"
  19. "dashoo.cn/backend/api/business/baseUser"
  20. "dashoo.cn/backend/api/business/oilsupplier/goodsaptitude"
  21. . "dashoo.cn/backend/api/controllers"
  22. "dashoo.cn/business2/parameter"
  23. "dashoo.cn/business2/userRole"
  24. "dashoo.cn/utils"
  25. . "github.com/linxGnu/goseaweedfs"
  26. )
  27. type OilGoodsAptitudeController struct {
  28. BaseController
  29. }
  30. // @Title 获取列表
  31. // @Description get user by token
  32. // @Success 200 {object} []goodsaptitude.OilGoodsAptitude
  33. // @router /list [get]
  34. func (this *OilGoodsAptitudeController) GetEntityList() {
  35. //获取分页信息
  36. page := this.GetPageInfoForm()
  37. where := " 1=1 "
  38. orderby := "Code"
  39. asc := true
  40. Order := this.GetString("Order")
  41. Prop := this.GetString("Prop")
  42. if Order != "" && Prop != "" {
  43. orderby = Prop
  44. if Order == "asc" {
  45. asc = true
  46. } else {
  47. asc = false
  48. }
  49. }
  50. Edition := this.GetString("Edition")
  51. CreateOn := this.GetString("CreateOn")
  52. Code := this.GetString("Code")
  53. Name := this.GetString("Name")
  54. BigClassName := this.GetString("BigClassName")
  55. BigClassCode := this.GetString("BigClassCode")
  56. MiddleClassName := this.GetString("MiddleClassName")
  57. SmallClassName := this.GetString("SmallClassName")
  58. GoodsName := this.GetString("GoodsName")
  59. GoodsLevel := this.GetString("GoodsLevel")
  60. GoodsDesc := this.GetString("GoodsDesc")
  61. Standard := this.GetString("Standard")
  62. CompanyType := this.GetString("CompanyType")
  63. if Edition != "" {
  64. where = where + " and Edition = '" + Edition + "'"
  65. }
  66. if Code != "" {
  67. where = where + " and Code like '%" + Code + "%'"
  68. }
  69. if Name != "" {
  70. where = where + " and Name like '%" + Name + "%'"
  71. }
  72. if BigClassName != "" {
  73. where = where + " and Name1 like '%" + BigClassName + "%'"
  74. }
  75. if BigClassCode != "" {
  76. where = where + " and Code1 like '%" + BigClassCode + "%'"
  77. }
  78. if MiddleClassName != "" {
  79. where = where + " and Name2 like '%" + MiddleClassName + "%'"
  80. }
  81. if SmallClassName != "" {
  82. where = where + " and Name3 like '%" + SmallClassName + "%'"
  83. }
  84. if GoodsName != "" {
  85. where = where + " and Name4 like '%" + GoodsName + "%'"
  86. }
  87. if GoodsLevel != "" {
  88. where = where + " and GoodsLevel like '%" + GoodsLevel + "%'"
  89. }
  90. if GoodsDesc != "" {
  91. where = where + " and GoodsDesc like '%" + GoodsDesc + "%'"
  92. }
  93. if Standard != "" {
  94. where = where + " and Standard '%" + Standard + "%'"
  95. }
  96. if CompanyType != "" {
  97. where = where + " and CompanyType '%" + CompanyType + "%'"
  98. }
  99. if CreateOn != "" {
  100. dates := strings.Split(CreateOn, ",")
  101. if len(dates) == 2 {
  102. minDate := dates[0]
  103. maxDate := dates[1]
  104. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  105. }
  106. }
  107. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  108. var list []goodsaptitude.OilGoodsAptitudeView
  109. total := svc.GetMyPagingEntitiesWithOrderBytbl(OilGoodsAptDetailViewName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  110. var datainfo DataInfo
  111. datainfo.Items = list
  112. datainfo.CurrentItemCount = total
  113. datainfo.PageIndex = page.CurrentPage
  114. datainfo.ItemsPerPage = page.Size
  115. this.Data["json"] = &datainfo
  116. this.ServeJSON()
  117. }
  118. // @Title 获取列表新导入的列表
  119. // @Description get user by token
  120. // @Success 200 {object} []goodsaptitude.OilGoodsAptitude
  121. // @router /importlist [get]
  122. func (this *OilGoodsAptitudeController) GetImportEntityList() {
  123. //获取分页信息
  124. page := this.GetPageInfoForm()
  125. where := " 1=1 "
  126. orderby := "Code"
  127. asc := true
  128. Order := this.GetString("Order")
  129. Prop := this.GetString("Prop")
  130. if Order != "" && Prop != "" {
  131. orderby = Prop
  132. if Order == "asc" {
  133. asc = true
  134. } else {
  135. asc = false
  136. }
  137. }
  138. Edition := this.GetString("Edition")
  139. CreateOn := this.GetString("CreateOn")
  140. Code := this.GetString("Code")
  141. Name := this.GetString("Name")
  142. BigClassName := this.GetString("BigClassName")
  143. BigClassCode := this.GetString("BigClassCode")
  144. MiddleClassName := this.GetString("MiddleClassName")
  145. SmallClassName := this.GetString("SmallClassName")
  146. GoodsName := this.GetString("GoodsName")
  147. GoodsLevel := this.GetString("GoodsLevel")
  148. GoodsDesc := this.GetString("GoodsDesc")
  149. Standard := this.GetString("Standard")
  150. CompanyType := this.GetString("CompanyType")
  151. if Edition != "" {
  152. where = where + " and Edition = '" + Edition + "'"
  153. }
  154. if Code != "" {
  155. where = where + " and Code like '%" + Code + "%'"
  156. }
  157. if Name != "" {
  158. where = where + " and Name like '%" + Name + "%'"
  159. }
  160. if BigClassName != "" {
  161. where = where + " and Name1 like '%" + BigClassName + "%'"
  162. }
  163. if BigClassCode != "" {
  164. where = where + " and Code1 like '%" + BigClassCode + "%'"
  165. }
  166. if MiddleClassName != "" {
  167. where = where + " and Name2 like '%" + MiddleClassName + "%'"
  168. }
  169. if SmallClassName != "" {
  170. where = where + " and Name3 like '%" + SmallClassName + "%'"
  171. }
  172. if GoodsName != "" {
  173. where = where + " and Name4 like '%" + GoodsName + "%'"
  174. }
  175. if GoodsLevel != "" {
  176. where = where + " and GoodsLevel like '%" + GoodsLevel + "%'"
  177. }
  178. if GoodsDesc != "" {
  179. where = where + " and GoodsDesc like '%" + GoodsDesc + "%'"
  180. }
  181. if Standard != "" {
  182. where = where + " and Standard '%" + Standard + "%'"
  183. }
  184. if CompanyType != "" {
  185. where = where + " and CompanyType '%" + CompanyType + "%'"
  186. }
  187. if CreateOn != "" {
  188. dates := strings.Split(CreateOn, ",")
  189. if len(dates) == 2 {
  190. minDate := dates[0]
  191. maxDate := dates[1]
  192. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  193. }
  194. }
  195. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  196. var list []goodsaptitude.OilGoodsAptitudeView
  197. total := svc.GetMyPagingEntitiesWithOrderBytbl(ImportOilGoodsAptDetailViewName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  198. var datainfo DataInfo
  199. datainfo.Items = list
  200. datainfo.CurrentItemCount = total
  201. datainfo.PageIndex = page.CurrentPage
  202. datainfo.ItemsPerPage = page.Size
  203. this.Data["json"] = &datainfo
  204. this.ServeJSON()
  205. }
  206. // @Title 获取列表2019版本
  207. // @Description
  208. // @Success 200 {object}
  209. // @router /list_2019 [get]
  210. func (this *OilGoodsAptitudeController) GetEntityList_2019() {
  211. //获取分页信息
  212. page := this.GetPageInfoForm()
  213. where := " 1=1 "
  214. orderby := "Code"
  215. asc := true
  216. Order := this.GetString("Order")
  217. Prop := this.GetString("Prop")
  218. if Order != "" && Prop != "" {
  219. orderby = Prop
  220. if Order == "asc" {
  221. asc = true
  222. } else {
  223. asc = false
  224. }
  225. }
  226. Edition := this.GetString("Edition")
  227. Code := this.GetString("Code")
  228. Name := this.GetString("Name")
  229. if Edition != "" {
  230. where = where + " and a.Edition = '" + Edition + "'"
  231. }
  232. if Code != "" {
  233. where = where + " and b.Code like '%" + Code + "%'"
  234. }
  235. if Name != "" {
  236. where = where + " and b.Name like '%" + Name + "%'"
  237. }
  238. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  239. var list []goodsaptitude.OilGoodsAptitude_2
  240. total := svc.GetList_2019(OilGoodsAptitudeName, OilGoodsAptitudeClassName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  241. var datainfo DataInfo
  242. datainfo.Items = list
  243. datainfo.CurrentItemCount = total
  244. datainfo.PageIndex = page.CurrentPage
  245. datainfo.ItemsPerPage = page.Size
  246. this.Data["json"] = &datainfo
  247. this.ServeJSON()
  248. }
  249. // @Title 获取字典列表
  250. // @Description get user by token
  251. // @Success 200 {object} map[string]interface{}
  252. // @router /dictlist [get]
  253. func (this *OilGoodsAptitudeController) GetDictList() {
  254. dictList := make(map[string]interface{})
  255. dictSvc := items.GetItemsService(utils.DBE)
  256. userSvc := baseUser.GetBaseUserService(utils.DBE)
  257. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  258. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", "")
  259. var userEntity userRole.Base_User
  260. userSvc.GetEntityById(this.User.Id, &userEntity)
  261. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId("", userEntity.Departmentid)
  262. dictList["AuditStep"] = dictSvc.GetKeyValueItems("AuditStep", this.User.AccCode)
  263. //var dictCustomer []svccustomer.Customer
  264. //customerSvc.GetEntitysByWhere("" + CustomerName, "", &dictCustomer)
  265. //dictList["EntrustCorp"] = &dictCustomer
  266. var datainfo DataInfo
  267. datainfo.Items = dictList
  268. this.Data["json"] = &datainfo
  269. this.ServeJSON()
  270. }
  271. // @Title 获取实体
  272. // @Description 获取实体
  273. // @Success 200 {object} goodsaptitude.OilGoodsAptitude
  274. // @router /get/:id [get]
  275. func (this *OilGoodsAptitudeController) GetEntity() {
  276. Id := this.Ctx.Input.Param(":id")
  277. var model goodsaptitude.OilGoodsAptitudeView
  278. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  279. //svc.GetEntityByIdBytbl(""+OilGoodsAptitudeName, Id, &model)
  280. where := " Id =" + Id
  281. svc.GetEntityByWhere(OilGoodsAptDetailViewName, where, &model)
  282. this.Data["json"] = &model
  283. this.ServeJSON()
  284. }
  285. // @Title 获取实体
  286. // @Description 获取实体
  287. // @Success 200 {object}
  288. // @router /get_2019/:id [get]
  289. func (this *OilGoodsAptitudeController) GetEntity_2019() {
  290. Id := this.Ctx.Input.Param(":id")
  291. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  292. var tempMap []map[string]string
  293. 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,
  294. a.F11,a.F12,a.F13,a.F14,a.F15,a.F16,a.F17,a.F18,a.F19,a.F20,
  295. a.F21,a.F22,a.F23,a.F24,a.F25,a.F26,a.F27,a.F28,a.F29,a.F30,
  296. a.F31,a.F32,a.F33,a.F34,a.F35,a.F36,a.F37,a.F38,a.F39,a.F40,
  297. a.F41,a.F42,a.F43,a.F44,a.F45,a.F46,b.Code, b.Name `
  298. sql += ` from ` + OilGoodsAptitudeName + ` a `
  299. sql += ` left join ` + OilGoodsAptitudeClassName + " b on b.Id = a.ClassId"
  300. sql += ` where a.Id='` + Id + `'`
  301. tempMap, _ = svc.DBE.QueryString(sql)
  302. this.Data["json"] = &tempMap
  303. this.ServeJSON()
  304. }
  305. // @Title 添加
  306. // @Description 新增
  307. // @Success 200 {object} controllers.Request
  308. // @router /add/:id [post]
  309. func (this *OilGoodsAptitudeController) AddEntity() {
  310. classId := this.Ctx.Input.Param(":id")
  311. var model goodsaptitude.OilGoodsAptitude
  312. var jsonBlob = this.Ctx.Input.RequestBody
  313. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  314. json.Unmarshal(jsonBlob, &model)
  315. model.CreateOn = time.Now()
  316. model.CreateBy = this.User.Realname
  317. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  318. model.ClassId, _ = strconv.Atoi(classId)
  319. //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  320. _, err := svc.InsertEntityBytbl(""+OilGoodsAptitudeName, &model)
  321. var errinfo ErrorDataInfo
  322. if err == nil {
  323. //新增
  324. errinfo.Message = "添加成功!"
  325. errinfo.Code = 0
  326. errinfo.Item = model.Id
  327. this.Data["json"] = &errinfo
  328. this.ServeJSON()
  329. } else {
  330. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  331. errinfo.Code = -1
  332. this.Data["json"] = &errinfo
  333. this.ServeJSON()
  334. }
  335. }
  336. // @Title 添加
  337. // @Description 新增
  338. // @Success 200 {object} controllers.Request
  339. // @router /add_2019 [post]
  340. func (this *OilGoodsAptitudeController) AddEntity_2019() {
  341. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  342. var model goodsaptitudeclass.OilGoodsAptitudeClass
  343. var jsonBlob = this.Ctx.Input.RequestBody
  344. json.Unmarshal(jsonBlob, &model)
  345. model.ParentId = -1
  346. model.Edition = "2"
  347. model.CreateOn = time.Now()
  348. model.CreateBy = this.User.Realname
  349. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  350. _, err := svc.InsertEntityBytbl(""+OilGoodsAptitudeClassName, &model)
  351. var model2 goodsaptitude.OilGoodsAptitude
  352. json.Unmarshal(jsonBlob, &model2)
  353. model2.ClassId = model.Id
  354. model2.Edition = "2"
  355. model2.CreateOn = time.Now()
  356. model2.CreateBy = this.User.Realname
  357. model2.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  358. _, err = svc.InsertEntityBytbl(""+OilGoodsAptitudeName, &model2)
  359. var errinfo ErrorDataInfo
  360. if err == nil {
  361. //新增
  362. errinfo.Message = "添加成功!"
  363. errinfo.Code = 0
  364. errinfo.Item = model2.Id
  365. this.Data["json"] = &errinfo
  366. this.ServeJSON()
  367. } else {
  368. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  369. errinfo.Code = -1
  370. this.Data["json"] = &errinfo
  371. this.ServeJSON()
  372. }
  373. }
  374. // @Title 修改实体
  375. // @Description 修改实体
  376. // @Success 200 {object} controllers.Request
  377. // @router /update/:id [post]
  378. func (this *OilGoodsAptitudeController) UpdateEntity() {
  379. id := this.Ctx.Input.Param(":id")
  380. var errinfo ErrorInfo
  381. if id == "" {
  382. errinfo.Message = "操作失败!请求信息不完整"
  383. errinfo.Code = -2
  384. this.Data["json"] = &errinfo
  385. this.ServeJSON()
  386. return
  387. }
  388. var model goodsaptitude.OilGoodsAptitude
  389. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  390. var jsonBlob = this.Ctx.Input.RequestBody
  391. json.Unmarshal(jsonBlob, &model)
  392. model.ModifiedOn = time.Now()
  393. model.ModifiedBy = this.User.Realname
  394. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  395. cols := []string{
  396. "Id",
  397. "Code",
  398. "Name",
  399. "BigClassName",
  400. "MiddleClassName",
  401. "SmallClassName",
  402. "GoodsName",
  403. "GoodsLevel",
  404. "GoodsDesc",
  405. "Standard",
  406. "CompanyType",
  407. "F01",
  408. "F02",
  409. "F03",
  410. "F04",
  411. "F05",
  412. "F06",
  413. "F07",
  414. "F08",
  415. "F09",
  416. "F10",
  417. "F11",
  418. "F12",
  419. "F13",
  420. "F14",
  421. "F15",
  422. "F16",
  423. "F17",
  424. "F18",
  425. "F19",
  426. "F20",
  427. "F21",
  428. "F22",
  429. "F23",
  430. "F24",
  431. "F25",
  432. "F26",
  433. "F27",
  434. "F28",
  435. "F29",
  436. "F30",
  437. "F31",
  438. "F32",
  439. "F33",
  440. "F34",
  441. "F35",
  442. "F36",
  443. "F37",
  444. "F38",
  445. "F39",
  446. "F40",
  447. "F41",
  448. "F42",
  449. "F43",
  450. "F44",
  451. "F45",
  452. "F46",
  453. "Remark",
  454. "DeletionStateCode",
  455. "CreateOn",
  456. "CreateUserId",
  457. "CreateBy",
  458. "ModifiedOn",
  459. "ModifiedUserId",
  460. "ModifiedBy",
  461. }
  462. err := svc.UpdateEntityBytbl(""+OilGoodsAptitudeName, id, &model, cols)
  463. if err == nil {
  464. errinfo.Message = "修改成功!"
  465. errinfo.Code = 0
  466. this.Data["json"] = &errinfo
  467. this.ServeJSON()
  468. } else {
  469. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  470. errinfo.Code = -1
  471. this.Data["json"] = &errinfo
  472. this.ServeJSON()
  473. }
  474. }
  475. // @Title 修改实体
  476. // @Description 修改实体
  477. // @Success 200 {object} controllers.Request
  478. // @router /update_2019/:id [post]
  479. func (this *OilGoodsAptitudeController) UpdateEntity_2019() {
  480. id := this.Ctx.Input.Param(":id")
  481. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  482. var errinfo ErrorInfo
  483. if id == "" {
  484. errinfo.Message = "操作失败!请求信息不完整"
  485. errinfo.Code = -2
  486. this.Data["json"] = &errinfo
  487. this.ServeJSON()
  488. return
  489. }
  490. var model goodsaptitude.OilGoodsAptitude
  491. var jsonBlob = this.Ctx.Input.RequestBody
  492. json.Unmarshal(jsonBlob, &model)
  493. model.ModifiedOn = time.Now()
  494. model.ModifiedBy = this.User.Realname
  495. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  496. cols := []string{
  497. "F01",
  498. "F02",
  499. "F03",
  500. "F04",
  501. "F05",
  502. "F06",
  503. "F07",
  504. "F08",
  505. "F09",
  506. "F10",
  507. "F11",
  508. "F12",
  509. "F13",
  510. "F14",
  511. "F15",
  512. "F16",
  513. "F17",
  514. "F18",
  515. "F19",
  516. "F20",
  517. "F21",
  518. "F22",
  519. "F23",
  520. "F24",
  521. "F25",
  522. "F26",
  523. "F27",
  524. "F28",
  525. "F29",
  526. "F30",
  527. "F31",
  528. "F32",
  529. "F33",
  530. "F34",
  531. "F35",
  532. "F36",
  533. "F37",
  534. "F38",
  535. "F39",
  536. "F40",
  537. "F41",
  538. "F42",
  539. "F43",
  540. "F44",
  541. "F45",
  542. "F46",
  543. "ModifiedOn",
  544. "ModifiedUserId",
  545. "ModifiedBy",
  546. }
  547. err := svc.UpdateEntityBytbl(""+OilGoodsAptitudeName, id, &model, cols)
  548. var model2 goodsaptitudeclass.OilGoodsAptitudeClass
  549. json.Unmarshal(jsonBlob, &model2)
  550. model2.ModifiedOn = time.Now()
  551. model2.ModifiedBy = this.User.Realname
  552. model2.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  553. cols2 := []string{
  554. "Code",
  555. "Name",
  556. "ModifiedOn",
  557. "ModifiedUserId",
  558. "ModifiedBy",
  559. }
  560. err = svc.UpdateEntityBytbl(""+OilGoodsAptitudeClassName, model.ClassId, &model2, cols2)
  561. if err == nil {
  562. errinfo.Message = "修改成功!"
  563. errinfo.Code = 0
  564. this.Data["json"] = &errinfo
  565. this.ServeJSON()
  566. } else {
  567. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  568. errinfo.Code = -1
  569. this.Data["json"] = &errinfo
  570. this.ServeJSON()
  571. }
  572. }
  573. // @Title 修改实体
  574. // @Description 修改实体
  575. // @Success 200 {object} controllers.Request
  576. // @router /updatecode/:id [post]
  577. func (this *OilGoodsAptitudeController) UpdateCodeEntity() {
  578. var errinfo ErrorInfo
  579. var err error
  580. id := this.Ctx.Input.Param(":id")
  581. if id == "" {
  582. errinfo.Message = "操作失败!请求信息不完整"
  583. errinfo.Code = -2
  584. this.Data["json"] = &errinfo
  585. this.ServeJSON()
  586. return
  587. }
  588. var classall goodsaptitude.OilGoodsAptitudeClassView
  589. var model goodsaptitudeclass.OilGoodsAptitudeClass
  590. var classmodel []goodsaptitudeclass.OilGoodsAptitudeClass
  591. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  592. var jsonBlob = this.Ctx.Input.RequestBody
  593. json.Unmarshal(jsonBlob, &classall)
  594. model.ModifiedOn = time.Now()
  595. model.ModifiedBy = this.User.Realname
  596. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  597. colsName := []string{"Name"}
  598. colsCode := []string{"Code"}
  599. //svc.GetEntityById(id, &model)
  600. if classall.Name1 != "" {
  601. where := " Name = '" + classall.Name1 + "' and Id <> " + utils.ToStr(classall.Id1)
  602. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  603. if len(classmodel) > 0 {
  604. errinfo.Message = "大类名称已存在,请重新添加!"
  605. errinfo.Code = -1
  606. this.Data["json"] = &errinfo
  607. this.ServeJSON()
  608. return
  609. } else {
  610. model.Name = classall.Name1
  611. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id1, &model, colsName)
  612. }
  613. }
  614. if classall.Name2 != "" {
  615. where := " Name = '" + classall.Name2 + "' and Id <> " + utils.ToStr(classall.Id2)
  616. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  617. if len(classmodel) > 0 {
  618. errinfo.Message = "中类名称已存在,请重新添加!"
  619. errinfo.Code = -1
  620. this.Data["json"] = &errinfo
  621. this.ServeJSON()
  622. return
  623. } else {
  624. model.Name = classall.Name2
  625. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id2, &model, colsName)
  626. }
  627. }
  628. if classall.Name3 != "" {
  629. where := " Name = '" + classall.Name3 + "' and Id <> " + utils.ToStr(classall.Id3)
  630. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  631. if len(classmodel) > 0 {
  632. errinfo.Message = "小类名称已存在,请重新添加!"
  633. errinfo.Code = -1
  634. this.Data["json"] = &errinfo
  635. this.ServeJSON()
  636. return
  637. } else {
  638. model.Name = classall.Name3
  639. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id3, &model, colsName)
  640. }
  641. }
  642. if classall.Name4 != "" {
  643. where := " Name = '" + classall.Name4 + "' and Id <> " + utils.ToStr(classall.Id4)
  644. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  645. if len(classmodel) > 0 {
  646. errinfo.Message = "品名已存在,请重新添加!"
  647. errinfo.Code = -1
  648. this.Data["json"] = &errinfo
  649. this.ServeJSON()
  650. return
  651. } else {
  652. model.Name = classall.Name4
  653. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id4, &model, colsName)
  654. }
  655. }
  656. if classall.Code1 != "" {
  657. where := " Code = " + classall.Code1 + " and Id <> " + utils.ToStr(classall.Id1)
  658. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  659. if len(classmodel) > 0 {
  660. errinfo.Message = "大类编码已存在,请重新添加!"
  661. errinfo.Code = -1
  662. this.Data["json"] = &errinfo
  663. this.ServeJSON()
  664. return
  665. } else {
  666. model.Code = classall.Code1
  667. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id1, &model, colsCode)
  668. }
  669. }
  670. if classall.Code2 != "" {
  671. where := " Code = " + classall.Code2 + " and Id <> " + utils.ToStr(classall.Id2)
  672. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  673. if len(classmodel) > 0 {
  674. errinfo.Message = "中类编码已存在,请重新添加!"
  675. errinfo.Code = -1
  676. this.Data["json"] = &errinfo
  677. this.ServeJSON()
  678. return
  679. } else {
  680. model.Code = classall.Code2
  681. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id2, &model, colsCode)
  682. }
  683. }
  684. if classall.Code3 != "" {
  685. where := " Code = " + classall.Code3 + " and Id <> " + utils.ToStr(classall.Id3)
  686. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  687. if len(classmodel) > 0 {
  688. errinfo.Message = "小类编码已存在,请重新添加!"
  689. errinfo.Code = -1
  690. this.Data["json"] = &errinfo
  691. this.ServeJSON()
  692. return
  693. } else {
  694. model.Code = classall.Code3
  695. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id3, &model, colsCode)
  696. }
  697. }
  698. if classall.Code4 != "" {
  699. where := " Code = " + classall.Code4 + " and Id <> " + utils.ToStr(classall.Id4)
  700. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  701. if len(classmodel) > 0 {
  702. errinfo.Message = "品名编码已存在,请重新添加!"
  703. errinfo.Code = -1
  704. this.Data["json"] = &errinfo
  705. this.ServeJSON()
  706. return
  707. } else {
  708. model.Code = classall.Code4
  709. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id4, &model, colsCode)
  710. }
  711. }
  712. if err == nil {
  713. errinfo.Message = "修改成功!"
  714. errinfo.Code = 0
  715. this.Data["json"] = &errinfo
  716. this.ServeJSON()
  717. } else {
  718. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  719. errinfo.Code = -1
  720. this.Data["json"] = &errinfo
  721. this.ServeJSON()
  722. }
  723. }
  724. // @Title 删除单条信息
  725. // @Description
  726. // @Success 200 {object} ErrorInfo
  727. // @Failure 403 :id 为空
  728. // @router /delete/:Id [delete]
  729. func (this *OilGoodsAptitudeController) DeleteEntity() {
  730. Id := this.Ctx.Input.Param(":Id")
  731. var errinfo ErrorInfo
  732. if Id == "" {
  733. errinfo.Message = "操作失败!请求信息不完整"
  734. errinfo.Code = -2
  735. this.Data["json"] = &errinfo
  736. this.ServeJSON()
  737. return
  738. }
  739. var model goodsaptitude.OilGoodsAptitude
  740. var entityempty goodsaptitude.OilGoodsAptitude
  741. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  742. opdesc := "删除-" + Id
  743. err := svc.DeleteOperationAndWriteLogBytbl(""+OilGoodsAptitudeName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "钻井日报")
  744. if err == nil {
  745. errinfo.Message = "删除成功"
  746. errinfo.Code = 0
  747. this.Data["json"] = &errinfo
  748. this.ServeJSON()
  749. } else {
  750. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  751. errinfo.Code = -1
  752. this.Data["json"] = &errinfo
  753. this.ServeJSON()
  754. }
  755. }
  756. // @Title get 查询
  757. // @Description get SampleType by token
  758. // @Success 200 {object} sampletype.SampleType
  759. // @router /goodsparentlist/:name [get]
  760. func (this *OilGoodsAptitudeController) GoodsParentList() {
  761. Name := this.Ctx.Input.Param(":name")
  762. if Name != "" {
  763. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  764. where1 := "1=1"
  765. where1 += " AND Name LIKE '%" + Name + "%' OR Code LIKE '" + Name + "%' "
  766. sqlStr := "SELECT Id, Code, Name, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass " +
  767. "WHERE " + where1 + " AND Edition='1' AND DeletionStateCode = 0 ORDER BY Code"
  768. list, _ := svc.DBE.QueryString(sqlStr)
  769. /*
  770. sql := "SELECT Id, Code, Name, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass " +
  771. "WHERE DeletionStateCode = 0 AND " + where1 + " OR Id = (" + sqlStr + ")" +" ORDER BY Code"
  772. list, _ := svc.DBE.QueryString(sql)*/
  773. var datainfo DataInfo
  774. datainfo.Items = list
  775. this.Data["json"] = &datainfo
  776. this.ServeJSON()
  777. }
  778. }
  779. // @Title get 获取子类
  780. // @Description get SampleType by token
  781. // @Success 200 {object} sampletype.SampleType
  782. // @router /goodschildlist/:id [get]
  783. func (this *OilGoodsAptitudeController) GoodsChildList() {
  784. ParentId := this.Ctx.Input.Param(":id")
  785. 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"
  786. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  787. list, _ := svc.DBE.QueryString(sqlStr)
  788. var datainfo DataInfo
  789. datainfo.Items = list
  790. this.Data["json"] = &datainfo
  791. this.ServeJSON()
  792. }
  793. // @Title get 获取子类
  794. // @Description get SampleType by token
  795. // @Success 200 {object} sampletype.SampleType
  796. // @router /goodschildlistbypid/:parentid [get]
  797. func (this *OilGoodsAptitudeController) GoodsChildLisByParentId() {
  798. ParentId := this.Ctx.Input.Param(":parentid")
  799. sqlStr := "SELECT o.Id, o.`Code`, o.`Name`, concat(o.Code, ' ', o.Name) as CodeName, o.ParentId, g.GoodsLevel," +
  800. " (CASE WHEN length(Code)>=8 THEN '1' ELSE '0' END) as Leaf FROM OilGoodsAptitudeClass o " +
  801. " LEFT JOIN `OilGoodsAptitude` g ON (g.ClassId = o.Id)" +
  802. " WHERE o.ParentId = '" + ParentId + "' AND o.Edition='1' AND o.DeletionStateCode = 0 order by o.Code"
  803. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  804. list, _ := svc.DBE.QueryString(sqlStr)
  805. var datainfo DataInfo
  806. datainfo.Items = list
  807. this.Data["json"] = &datainfo
  808. this.ServeJSON()
  809. }
  810. // @Title get 导出ex
  811. // @Description get SampleType by token
  812. // @Success 200 {object} sampletype.SampleType
  813. // @router /exportexcelall [get]
  814. func (this *OilGoodsAptitudeController) ExportExcelAll() {
  815. //获取分页信息
  816. //page := this.GetPageInfoForm()
  817. where := " 1=1 "
  818. orderby := "Code"
  819. asc := true
  820. Order := this.GetString("Order")
  821. Prop := this.GetString("Prop")
  822. if Order != "" && Prop != "" {
  823. orderby = Prop
  824. if Order == "asc" {
  825. asc = true
  826. } else {
  827. asc = false
  828. }
  829. }
  830. Edition := this.GetString("Edition")
  831. if Edition != "" {
  832. where = where + " and Edition = '" + Edition + "'"
  833. }
  834. t := time.Now()
  835. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  836. var list []goodsaptitude.OilGoodsAptitudeView
  837. svc.GetMyPagingEntitiesWithOrderBytbl(OilGoodsAptDetailViewName, 0, 0, orderby, asc, &list, where)
  838. var title []string
  839. filetitle := "物资类"
  840. //自定义显示列
  841. showcolumnarr := this.GetString("showcolumnarr")
  842. showcolumnnamearr := this.GetString("showcolumnnamearr")
  843. titlestring := showcolumnnamearr
  844. title = strings.Split(titlestring, ",")
  845. f := xlsx.NewFile()
  846. sheet, _ := f.AddSheet(filetitle)
  847. //rowhead := sheet.AddRow()
  848. //rowhead.WriteSlice(&title, -1)
  849. cellname := strings.Split(showcolumnarr, ",")
  850. row := sheet.AddRow()
  851. row.WriteSlice(&cellname, -1)
  852. for _, item := range list {
  853. var enumModel goodsaptitude.OilGoodsAptitudeView
  854. tmpModel := &item
  855. enumModel = *tmpModel
  856. immumodel := reflect.ValueOf(&enumModel)
  857. elem := immumodel.Elem()
  858. row := sheet.AddRow()
  859. for _, name := range title {
  860. cell := row.AddCell()
  861. if strings.HasPrefix(name, "F") {
  862. var val = elem.FieldByName(name).String()
  863. if val == "1" {
  864. cell.Value = "是"
  865. } else {
  866. cell.Value = ""
  867. }
  868. } else {
  869. cell.Value = elem.FieldByName(name).String()
  870. }
  871. }
  872. }
  873. for c, cl := 0, len(sheet.Cols); c < cl; c++ {
  874. sheet.Cols[c].Width = 20
  875. }
  876. //this.SaveSampleXlsx(filetitle, title, showcolumnarr, list, f)
  877. dir := "static/file/excel/report/" + this.GetAccode()
  878. SaveDirectory(dir)
  879. path := dir + "/" + utils.TimeFormat(time.Now(), "200612") + filetitle + ".xlsx"
  880. f.Save(path)
  881. var sw *Seaweed
  882. var filer []string
  883. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  884. filer = []string{_filer}
  885. }
  886. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  887. _, _, fID, _ := sw.UploadFile(path, "", "")
  888. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  889. os.Remove(path)
  890. fmt.Println("==retDocWatermarkUrl==", retDocUrl)
  891. this.Data["json"] = retDocUrl
  892. this.ServeJSON()
  893. elapsed := time.Since(t)
  894. fmt.Println(elapsed)
  895. }
  896. // @Title get 导出ex
  897. // @Description get SampleType by token
  898. // @Success 200 {object} sampletype.SampleType
  899. // @router /exportexcelall2019 [get]
  900. func (this *OilGoodsAptitudeController) ExportExcelAll2019() {
  901. //获取分页信息
  902. //page := this.GetPageInfoForm()
  903. where := " 1=1 "
  904. orderby := "Code"
  905. asc := true
  906. Order := this.GetString("Order")
  907. Prop := this.GetString("Prop")
  908. if Order != "" && Prop != "" {
  909. orderby = Prop
  910. if Order == "asc" {
  911. asc = true
  912. } else {
  913. asc = false
  914. }
  915. }
  916. Edition := this.GetString("Edition")
  917. if Edition != "" {
  918. where = where + " and a.Edition = '" + Edition + "'"
  919. }
  920. t := time.Now()
  921. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  922. var list []goodsaptitude.OilGoodsAptitude_2
  923. svc.GetList_2019(OilGoodsAptitudeName, OilGoodsAptitudeClassName, 0, 0, orderby, asc, &list, where)
  924. var title []string
  925. filetitle := "物资类(顶级)"
  926. //自定义显示列
  927. showcolumnarr := this.GetString("showcolumnarr")
  928. showcolumnnamearr := this.GetString("showcolumnnamearr")
  929. titlestring := showcolumnnamearr
  930. title = strings.Split(titlestring, ",")
  931. f := xlsx.NewFile()
  932. sheet, _ := f.AddSheet(filetitle)
  933. cellname := strings.Split(showcolumnarr, ",")
  934. row := sheet.AddRow()
  935. row.WriteSlice(&cellname, -1)
  936. for _, item := range list {
  937. var enumModel goodsaptitude.OilGoodsAptitude_2
  938. tmpModel := &item
  939. enumModel = *tmpModel
  940. immumodel := reflect.ValueOf(&enumModel)
  941. elem := immumodel.Elem()
  942. row := sheet.AddRow()
  943. for _, name := range title {
  944. cell := row.AddCell()
  945. if strings.HasPrefix(name, "F") {
  946. var val = elem.FieldByName(name).String()
  947. if val == "1" {
  948. cell.Value = "是"
  949. } else {
  950. cell.Value = ""
  951. }
  952. } else {
  953. cell.Value = elem.FieldByName(name).String()
  954. }
  955. }
  956. }
  957. for c, cl := 0, len(sheet.Cols); c < cl; c++ {
  958. sheet.Cols[c].Width = 20
  959. }
  960. dir := "static/file/excel/report/" + this.GetAccode()
  961. SaveDirectory(dir)
  962. path := dir + "/" + utils.TimeFormat(time.Now(), "200612") + filetitle + ".xlsx"
  963. f.Save(path)
  964. var sw *Seaweed
  965. var filer []string
  966. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  967. filer = []string{_filer}
  968. }
  969. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  970. _, _, fID, _ := sw.UploadFile(path, "", "")
  971. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  972. os.Remove(path)
  973. fmt.Println("==retDocWatermarkUrl==", retDocUrl)
  974. this.Data["json"] = retDocUrl
  975. this.ServeJSON()
  976. elapsed := time.Since(t)
  977. fmt.Println(elapsed)
  978. }
  979. // @Title get 导入excel
  980. // @Description get SampleType by token
  981. // @Success 200 {object} sampletype.SampleType
  982. // @router /importexcel [get]
  983. func (this *OilGoodsAptitudeController) ImportExcel() {
  984. url := this.GetString("ExcelUrl")
  985. var errorinfo ErrorInfo
  986. if url == "" {
  987. errorinfo.Code = -2
  988. errorinfo.Message = "导入失败!"
  989. this.Data["json"] = &errorinfo
  990. this.ServeJSON()
  991. }
  992. session := utils.DBE.NewSession()
  993. err := session.Begin()
  994. svc := goodsaptitude.GetOilGoodsAptitudeSession(session)
  995. err = svc.TruncateTable(Tmp_OilGoodsAptitudeName)
  996. if err != nil {
  997. session.Rollback()
  998. errorinfo.Code = -2
  999. errorinfo.Message = "导入失败!"
  1000. this.Data["json"] = &errorinfo
  1001. this.ServeJSON()
  1002. }
  1003. err = svc.TruncateTable(Tmp_OilGoodsAptitudeClassName)
  1004. if err != nil {
  1005. session.Rollback()
  1006. errorinfo.Code = -2
  1007. errorinfo.Message = "导入失败!"
  1008. this.Data["json"] = &errorinfo
  1009. this.ServeJSON()
  1010. }
  1011. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx"
  1012. utils.DownloadFile(url, "temp.xlsx", _dir)
  1013. t := time.Now()
  1014. filePath := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx/temp.xlsx"
  1015. xlFile, err := xlsx.OpenFile(filePath)
  1016. var errLineNum string
  1017. //excelFileName := "F:/物资类项目与资质对照表-2017.xlsx"
  1018. if err != nil {
  1019. fmt.Printf("open failed: %s\n", err)
  1020. }
  1021. var sheet = xlFile.Sheets[0]
  1022. Fstrs := svc.GetFCode()
  1023. Fstrs = "GoodsLevel,GoodsDesc,Standard,CompanyType," + Fstrs
  1024. columnArr := strings.Split(Fstrs, ",")
  1025. defer func() {
  1026. session.Close()
  1027. }()
  1028. codemap := make(map[string]int)
  1029. for i := 3; i < len(sheet.Rows); i++ {
  1030. lineNo := strconv.Itoa(i + 1)
  1031. this.OperationCell(svc, lineNo, columnArr, codemap, sheet.Rows[i].Cells, &errLineNum)
  1032. }
  1033. os.Remove(filePath)
  1034. if errLineNum != "" {
  1035. session.Rollback()
  1036. errorinfo.Code = -1
  1037. errorinfo.Message = "导入失败!错误行号:" + errLineNum
  1038. this.Data["json"] = &errorinfo
  1039. this.ServeJSON()
  1040. } else {
  1041. session.Commit()
  1042. elapsed := time.Since(t)
  1043. log.Println(elapsed)
  1044. errorinfo.Code = 0
  1045. errorinfo.Message = "导入成功!"
  1046. this.Data["json"] = &errorinfo
  1047. this.ServeJSON()
  1048. }
  1049. }
  1050. func (this *OilGoodsAptitudeController) OperationCell(svc *goodsaptitude.OilGoodsAptitudeSession, lineNo string, columnArr []string, codemap map[string]int, cellsArr []*xlsx.Cell, errLineNum *string) {
  1051. defer func() {
  1052. if err := recover(); err != nil {
  1053. log.Println("err"+lineNo, err)
  1054. *errLineNum += lineNo + ","
  1055. }
  1056. }()
  1057. parentId := 0
  1058. classId := 0
  1059. cellsArrLen := len(cellsArr)
  1060. cellD := strings.TrimSpace(cellsArr[3].String())
  1061. var valstr = ""
  1062. for idx, cell := range cellsArr {
  1063. if idx < 4 {
  1064. cellstr := cell.String()
  1065. //fmt.Printf("%s\n", cellstr)
  1066. if strings.TrimSpace(cellstr) == "" {
  1067. break
  1068. }
  1069. cellArr := strings.Fields(cellstr)
  1070. //id := sessionsvc.SelectGoodsAptitudeClassCode(cellArr[0])
  1071. var entity goodsaptitudeclass.Tmp_OilGoodsAptitudeClass
  1072. _, has := codemap[cellArr[0]]
  1073. if !has {
  1074. if idx != 0 {
  1075. upcellstr := cellsArr[idx-1].String()
  1076. upcellArr := strings.Fields(upcellstr)
  1077. parentId = codemap[upcellArr[0]]
  1078. }
  1079. entity.Code = cellArr[0]
  1080. entity.Name = cellArr[1]
  1081. entity.Edition = "1"
  1082. entity.ParentId = parentId
  1083. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1084. entity.CreateBy = this.User.Realname
  1085. entity.CreateOn = time.Now()
  1086. _, err := svc.InsertEntityBytbl(Tmp_OilGoodsAptitudeClassName, &entity)
  1087. if err != nil {
  1088. panic(err)
  1089. break
  1090. }
  1091. classId = entity.Id
  1092. if idx != 3 {
  1093. codemap[cellArr[0]] = entity.Id
  1094. }
  1095. }
  1096. }
  1097. if idx >= 4 {
  1098. valstr += "'" + cellsArr[idx].String() + "',"
  1099. }
  1100. }
  1101. if cellD != "" {
  1102. valstr = strings.Trim(valstr, ",")
  1103. valstr = strings.Replace(valstr, "是", "1", -1)
  1104. log.Println(cellsArr[3].String() + "==" + valstr)
  1105. var columnstr = ""
  1106. for l := 0; l < cellsArrLen-4; l++ {
  1107. columnstr += columnArr[l] + ","
  1108. }
  1109. columnstr = strings.Trim(columnstr, ",")
  1110. err := svc.InsertTmpGoodsAptitude(strconv.Itoa(classId), columnstr, valstr)
  1111. if err != nil {
  1112. panic(err)
  1113. }
  1114. }
  1115. }
  1116. // @Title get 清空导入的信息
  1117. // @Description get SampleType by token
  1118. // @Success 200 {object} sampletype.SampleType
  1119. // @router /truncateimport [get]
  1120. func (this *OilGoodsAptitudeController) TruncateImport() {
  1121. session := utils.DBE.NewSession()
  1122. err := session.Begin()
  1123. defer session.Close()
  1124. svc := goodsaptitude.GetOilGoodsAptitudeSession(session)
  1125. err = svc.TruncateTable(Tmp_OilGoodsAptitudeName)
  1126. var errorinfo ErrorInfo
  1127. if err != nil {
  1128. session.Rollback()
  1129. errorinfo.Code = -1
  1130. errorinfo.Message = "删除失败!"
  1131. this.Data["json"] = &errorinfo
  1132. this.ServeJSON()
  1133. }
  1134. err = svc.TruncateTable(Tmp_OilGoodsAptitudeClassName)
  1135. if err != nil {
  1136. session.Rollback()
  1137. errorinfo.Code = -1
  1138. errorinfo.Message = "删除失败!"
  1139. this.Data["json"] = &errorinfo
  1140. this.ServeJSON()
  1141. }
  1142. session.Commit()
  1143. errorinfo.Code = 0
  1144. errorinfo.Message = "删除成功!"
  1145. this.Data["json"] = &errorinfo
  1146. this.ServeJSON()
  1147. }
  1148. // @Title 将导入的数据 导入到正式表
  1149. // @Description get SampleType by token
  1150. // @Success 200 {object} sampletype.SampleType
  1151. // @router /insertgoodsaptitude [get]
  1152. func (this *OilGoodsAptitudeController) InsertGoodsAptitude() {
  1153. session := utils.DBE.NewSession()
  1154. err := session.Begin()
  1155. defer session.Close()
  1156. svc := goodsaptitude.GetOilGoodsAptitudeSession(session)
  1157. err = svc.InsertGoodsAptitude(Tmp_OilGoodsAptitudeName, OilGoodsAptitudeName)
  1158. var errinfo ErrorInfo
  1159. if err != nil {
  1160. session.Rollback()
  1161. errinfo.Code = -1
  1162. errinfo.Message = "跟新失败!"
  1163. this.Data["josn"] = &errinfo
  1164. this.ServeJSON()
  1165. }
  1166. err = svc.InsertGoodsAptitude(Tmp_OilGoodsAptitudeClassName, OilGoodsAptitudeClassName)
  1167. if err != nil {
  1168. session.Rollback()
  1169. errinfo.Code = -1
  1170. errinfo.Message = "跟新失败!"
  1171. this.Data["json"] = &errinfo
  1172. this.ServeJSON()
  1173. }
  1174. session.Commit()
  1175. errinfo.Code = 0
  1176. errinfo.Message = "跟新成功!"
  1177. this.Data["json"] = &errinfo
  1178. this.ServeJSON()
  1179. }
  1180. // @Title 更新企业的准入项及资质
  1181. // @Description get SampleType by token
  1182. // @Success 200 {object} sampletype.SampleType
  1183. // @router /updatasuppiercertsub [get]
  1184. func (this *OilGoodsAptitudeController) UpdataSuppierCertSub() {
  1185. //excelFileName := "F:/ssa.xlsx"
  1186. //xlFile, _ := xlsx.OpenFile(excelFileName)
  1187. //var sheet = xlFile.Sheets[0]
  1188. t := time.Now()
  1189. goodsvc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  1190. goodsvc.TruncateTable(TmpOilSupplierCertSubName)
  1191. supsvc := supplier.GetOilSupplierService(utils.DBE)
  1192. var suppliercertList []suppliercert.OilSupplierCert
  1193. where := "SupplierTypeCode='01' AND OutsideFlog = '' AND (InFlag IN ('1','2')) "
  1194. supsvc.GetEntities(&suppliercertList, where)
  1195. var goodsaptitudeClassList []goodsaptitudeclass.OilGoodsAptitudeClass
  1196. whereclass := "LENGTH(CODE) = 8 "
  1197. supsvc.GetEntities(&goodsaptitudeClassList, whereclass)
  1198. var colsname = []string{"Name"}
  1199. var colsLevel = []string{"GoodsLevel"}
  1200. for _, suppliercert := range suppliercertList {
  1201. //row := sheet.AddRow()
  1202. //cell := row.AddCell()
  1203. //cell.Value = strconv.Itoa(suppliercert.SupplierId)
  1204. log.Println(suppliercert.SupplierId)
  1205. var supplierCertSubList []suppliercertsub.OilSupplierCertSub
  1206. wheresup := "SupplierId = " + strconv.Itoa(suppliercert.SupplierId) + " and SupplierTypeCode='01' AND Type IN ('1', '3')"
  1207. supsvc.GetEntities(&supplierCertSubList, wheresup)
  1208. fmt.Println(len(supplierCertSubList))
  1209. // 准入项
  1210. //for idx, supplierCertSub := range supplierCertSubList {
  1211. for idx := 0; idx < len(supplierCertSubList); idx++ {
  1212. //row := sheet.AddRow()
  1213. //cell := row.AddCell()
  1214. //cell.Value = "删除"
  1215. supplierCertSub := supplierCertSubList[idx]
  1216. decCode := supplierCertSub.Code
  1217. // 物资类的准入编码
  1218. for _, goodsaptitudeClass := range goodsaptitudeClassList {
  1219. // 如果编码相同的后 判断有没有改名 然后查询准入项需要哪些资质 去查资质表里有没有这些资质 没有就删除这个准入项
  1220. if supplierCertSub.Code == goodsaptitudeClass.Code {
  1221. decCode = ""
  1222. goodsAptitudeNameArr := this.GetGoodsAptitudeName(strconv.Itoa(goodsaptitudeClass.Id), strconv.Itoa(supplierCertSub.IsManufacturer))
  1223. for _, val := range goodsAptitudeNameArr {
  1224. var supplierFile supplierfile.OilSupplierFile
  1225. where := "SupplierId=" + strconv.Itoa(suppliercert.SupplierId) + " and NeedFileType='" + val + "'" + " and SupplierTypeCode IN ('000', '01')"
  1226. has := supsvc.GetEntityByWhere(OilSupplierFileName, where, &supplierFile)
  1227. if !has {
  1228. //cell := row.AddCell()
  1229. //cell.Value = supplierCertSub.Code + " " + supplierCertSub.Name
  1230. log.Println(supplierCertSub.Code + "====" + val)
  1231. //wheredel := "Id = " + strconv.Itoa(supplierCertSub.Id)
  1232. //supsvc.DeleteEntityBytbl(OilSupplierCertSubName, wheredel)
  1233. supsvc.InsertEntityBytbl(TmpOilSupplierCertSubName, supplierCertSub)
  1234. break
  1235. }
  1236. if supplierCertSub.Name != goodsaptitudeClass.Name {
  1237. //row := sheet.AddRow()
  1238. //cell := row.AddCell()
  1239. //cell.Value = supplierCertSub.Code + ":" + supplierCertSub.Name + "==" + goodsaptitudeClass.Name
  1240. var entity suppliercertsub.OilSupplierCertSub
  1241. entity.Name = goodsaptitudeClass.Name
  1242. where := "Id = " + strconv.Itoa(supplierCertSub.Id)
  1243. supsvc.UpdateEntityBywheretbl(OilSupplierCertSubName, &entity, colsname, where)
  1244. }
  1245. var goodsAptitude goodsaptitude.OilGoodsAptitude
  1246. whereg := "ClassId = " + strconv.Itoa(goodsaptitudeClass.Id)
  1247. supsvc.GetEntity(&goodsAptitude, whereg)
  1248. if goodsAptitude.GoodsLevel != supplierCertSub.GoodsLevel {
  1249. var entity suppliercertsub.OilSupplierCertSub
  1250. entity.GoodsLevel = goodsAptitude.GoodsLevel
  1251. where := "Id = " + strconv.Itoa(supplierCertSub.Id)
  1252. supsvc.UpdateEntityBywheretbl(OilSupplierCertSubName, &entity, colsLevel, where)
  1253. }
  1254. }
  1255. break
  1256. }
  1257. }
  1258. if decCode != "" {
  1259. //wheredel := "Code = '" + decCode + "'"
  1260. //supsvc.DeleteEntityBytbl(OilSupplierCertSubName, wheredel)
  1261. supsvc.InsertEntityBytbl(TmpOilSupplierCertSubName, supplierCertSub)
  1262. }
  1263. //cell1 := row.AddCell()
  1264. //cell1.Value = decCode
  1265. }
  1266. }
  1267. elapsed := time.Since(t)
  1268. log.Println(elapsed)
  1269. var errinfo ErrorInfo
  1270. errinfo.Code = 0
  1271. errinfo.Message = "更新完成!"
  1272. this.Data["json"] = &errinfo
  1273. this.ServeJSON()
  1274. //xlFile.Save(excelFileName)
  1275. }
  1276. func (this *OilGoodsAptitudeController) GetGoodsAptitudeName(classId, IsManuf string) []string {
  1277. var goodsAptitudeName string
  1278. var goodsAptitudeList []goodsaptitude.OilGoodsAptitudeF
  1279. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  1280. where := "ClassId=" + classId
  1281. svc.GetGoodsAptitudeF(&goodsAptitudeList, where)
  1282. for _, goodsAptitude := range goodsAptitudeList {
  1283. t := reflect.TypeOf(goodsAptitude)
  1284. v := reflect.ValueOf(goodsAptitude)
  1285. for k := 0; k < t.NumField(); k++ {
  1286. if v.Field(k).Interface() == "1" {
  1287. var tableHeader tableheader.BaseTableheader
  1288. where := "Code='" + t.Field(k).Name + "' and IsManuf in ('0','" + IsManuf + "')"
  1289. has := svc.GetEntityByWhere(BaseTableHeader, where, &tableHeader)
  1290. if has {
  1291. goodsAptitudeName += tableHeader.Name + ","
  1292. }
  1293. }
  1294. }
  1295. }
  1296. return strings.Split(goodsAptitudeName, ",")
  1297. }
  1298. // @Title 获取所有
  1299. // @Description
  1300. // @Success 200 {object}
  1301. // @router /getcompanylist [post]
  1302. func (this *OilGoodsAptitudeController) GetTList() {
  1303. var model supplier.OilSupplierSelect
  1304. var model1 supplier.RegCapitalRange //注册资金范围
  1305. //var model2 supplier.NeedFileTypeStruct //资质结构体
  1306. var jsonBlob = this.Ctx.Input.RequestBody
  1307. json.Unmarshal(jsonBlob, &model)
  1308. json.Unmarshal(jsonBlob, &model1)
  1309. //json.Unmarshal(jsonBlob, &model2)
  1310. // //获取分页信息
  1311. page := this.GetPageInfoForm()
  1312. where := " 1=1 AND b.InFlag in (1,2,3) AND b.Status = '8' and b.SupplierTypeCode = '01' AND t.SupplierId IS NOT NULL "
  1313. orderby := "a.Id"
  1314. asc := true
  1315. Order := this.GetString("Order")
  1316. Prop := this.GetString("Prop")
  1317. CheckUId := this.GetString("CheckUId")
  1318. FullId := this.GetString("FullId")
  1319. if Order != "" && Prop != "" {
  1320. orderby = Prop
  1321. if Order == "desc" {
  1322. asc = false
  1323. }
  1324. }
  1325. leftjoin := ""
  1326. //准入证号
  1327. if model.AccessCardNo != "" {
  1328. where = where + " and b.AccessCardNo like '%" + model.AccessCardNo + "%'"
  1329. }
  1330. //企业名称
  1331. if model.SupplierName != "" {
  1332. where = where + " and a.SupplierName like '%" + model.SupplierName + "%'"
  1333. }
  1334. if model.OldSupplierName != "" {
  1335. where = where + " and OldSupplierName like '%" + model.OldSupplierName + "%'"
  1336. }
  1337. if FullId != "" {
  1338. where = where + " and f.Id = '" + FullId + "'"
  1339. }
  1340. if CheckUId != "" {
  1341. where = where + " and g.CheckUnitId = '" + CheckUId + "'"
  1342. }
  1343. //准入标识 1 准入 2 暂停 3取消
  1344. if model.InFlag != "" {
  1345. where = where + " and b.InFlag = '" + model.InFlag + "'"
  1346. }
  1347. //法人
  1348. if model.LegalPerson != "" {
  1349. where = where + " and a.LegalPerson like '%" + model.LegalPerson + "%'"
  1350. }
  1351. //联系人
  1352. if model.ContactName != "" {
  1353. where = where + " and a.ContactName like '%" + model.ContactName + "%'"
  1354. }
  1355. //统一社会信用代码
  1356. if model.CommercialNo != "" {
  1357. where = where + " and a.CommercialNo like '%" + model.CommercialNo + "%'"
  1358. }
  1359. //开户银行
  1360. if model.DepositBank != "" {
  1361. where = where + " and a.DepositBank like '%" + model.DepositBank + "%'"
  1362. }
  1363. //HSE审查
  1364. if model.HseTraining != "" {
  1365. where = where + " and a.HseTraining = '" + model.HseTraining + "'"
  1366. }
  1367. //公司类型
  1368. if model.CompanyType != "" {
  1369. where = where + " and a.CompanyType like '%" + model.CompanyType + "%'"
  1370. }
  1371. //成立时间
  1372. SetupTime := this.GetString("SetupTime")
  1373. if SetupTime != "" {
  1374. where = where + " and a.SetupTime ='" + SetupTime + "'"
  1375. }
  1376. //注册资金范围
  1377. if model1.RegCapital1 != "" {
  1378. where = where + " and a.RegCapital >= '" + model1.RegCapital1 + "'"
  1379. }
  1380. if model1.RegCapital2 != "" {
  1381. where = where + " and a.RegCapital <= '" + model1.RegCapital2 + "'"
  1382. }
  1383. //注册省份
  1384. if model.Province != "" {
  1385. where = where + " and a.Province = '" + model.Province + "'"
  1386. }
  1387. //注册市
  1388. if model.City != "" {
  1389. where = where + " and a.City = '" + model.City + "'"
  1390. }
  1391. //注册区
  1392. if model.Street != "" {
  1393. where = where + " and a.Street = '" + model.Street + "'"
  1394. }
  1395. //注册详细地址
  1396. if model.Address != "" {
  1397. where = where + " and a.Address like '%" + model.Address + "%'"
  1398. }
  1399. if model.LinkProvince != "" {
  1400. where = where + " and a.LinkProvince = '" + model.LinkProvince + "'"
  1401. }
  1402. if model.LinkCity != "" {
  1403. where = where + " and a.LinkCity = '" + model.LinkCity + "'"
  1404. }
  1405. if model.LinkStreet != "" {
  1406. where = where + " and a.LinkStreet = '" + model.LinkStreet + "'"
  1407. }
  1408. if model.LinkAddress != "" {
  1409. where = where + " and a.LinkAddress like '%" + model.LinkAddress + "%'"
  1410. }
  1411. //营业范围
  1412. if model.BusinessScope != "" {
  1413. where = where + " and a.BusinessScope like '%" + model.BusinessScope + "%'"
  1414. }
  1415. CreateOn := this.GetString("CreateOn")
  1416. if CreateOn != "" {
  1417. dates := strings.Split(CreateOn, ",")
  1418. if len(dates) == 2 {
  1419. minDate := dates[0]
  1420. maxDate := dates[1]
  1421. where = where + " and a.CreateOn>='" + minDate + "' and a.CreateOn<='" + maxDate + "'"
  1422. }
  1423. }
  1424. a := model.InStyle
  1425. fmt.Println(a)
  1426. //准入方式
  1427. if model.InStyle != "" {
  1428. if model.InStyle == "0" {
  1429. where = where + " and b.InStyle in ('2','3','4','5')"
  1430. } else {
  1431. where = where + " and b.InStyle ='" + model.InStyle + "'"
  1432. }
  1433. }
  1434. having := ""
  1435. //准入范围
  1436. if model.CerSubName != "" {
  1437. having = " having CerSubName like '%" + model.CerSubName + "%' "
  1438. leftjoin = "left join " + OilSupplierCertSubName + " d on d.SupplierCertId = b.Id "
  1439. }
  1440. //资质
  1441. if model.NeedFileType != "" {
  1442. having = " having NeedFileType like '%" + model.NeedFileType + "%' "
  1443. }
  1444. if model.CerSubName != "" && model.NeedFileType != "" {
  1445. having = " having CerSubName like '%" + model.CerSubName + "%' and NeedFileType like '%" + model.NeedFileType + "%' "
  1446. leftjoin = "left join " + OilSupplierCertSubName + " d on d.SupplierCertId = b.Id "
  1447. }
  1448. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  1449. var list []supplier.OilSupplierSelect
  1450. total := svc.GetMyPagingDelEntitiesWithOrderBytbl(OilSupplierName, OilSupplierCertName, OilInfoChangeName, OilCorporateInfoName, OilSupplierCertSubName,
  1451. OilSupplierFileName, page.CurrentPage, page.Size, orderby, asc, &list, where, having, leftjoin)
  1452. var datainfo DataInfo
  1453. datainfo.Items = list
  1454. datainfo.CurrentItemCount = total
  1455. datainfo.PageIndex = page.CurrentPage
  1456. datainfo.ItemsPerPage = page.Size
  1457. this.Data["json"] = &datainfo
  1458. this.ServeJSON()
  1459. }
  1460. // @Title 获取删除的准入项
  1461. // @Description get user by token
  1462. // @Success 200 {object} []suppliercertsub.OilSupplierCertSub
  1463. // @router /delcertsublist [get]
  1464. func (this *OilGoodsAptitudeController) GetDelCertSubList() {
  1465. //获取分页信息
  1466. page := this.GetPageInfoForm()
  1467. where := " 1=1 "
  1468. orderby := "Id"
  1469. asc := false
  1470. Order := this.GetString("Order")
  1471. Prop := this.GetString("Prop")
  1472. if Order != "" && Prop != "" {
  1473. orderby = Prop
  1474. if Order == "asc" {
  1475. asc = true
  1476. }
  1477. }
  1478. Id := this.GetString("Id")
  1479. SupplierId := this.GetString("SupplierId")
  1480. SupplierCertId := this.GetString("SupplierCertId")
  1481. SupplierTypeCode := this.GetString("SupplierTypeCode")
  1482. Code := this.GetString("Code")
  1483. Name := this.GetString("Name")
  1484. Remark := this.GetString("Remark")
  1485. IsDelete := this.GetString("IsDelete")
  1486. CreateOn := this.GetString("CreateOn")
  1487. CreateUserId := this.GetString("CreateUserId")
  1488. CreateBy := this.GetString("CreateBy")
  1489. ModifiedOn := this.GetString("ModifiedOn")
  1490. ModifiedUserId := this.GetString("ModifiedUserId")
  1491. ModifiedBy := this.GetString("ModifiedBy")
  1492. if Id != "" {
  1493. where = where + " and Id like '%" + Id + "%'"
  1494. }
  1495. if SupplierId != "" {
  1496. where = where + " and SupplierId like '%" + SupplierId + "%'"
  1497. }
  1498. if SupplierCertId != "" {
  1499. where = where + " and SupplierCertId = '" + SupplierCertId + "'"
  1500. }
  1501. if SupplierTypeCode != "" {
  1502. where = where + " and SupplierTypeCode = '" + SupplierTypeCode + "'"
  1503. }
  1504. if Code != "" {
  1505. where = where + " and Code like '%" + Code + "%'"
  1506. }
  1507. if Name != "" {
  1508. where = where + " and Name like '%" + Name + "%'"
  1509. }
  1510. if Remark != "" {
  1511. where = where + " and Remark like '%" + Remark + "%'"
  1512. }
  1513. if IsDelete != "" {
  1514. where = where + " and IsDelete like '%" + IsDelete + "%'"
  1515. }
  1516. if CreateUserId != "" {
  1517. where = where + " and CreateUserId like '%" + CreateUserId + "%'"
  1518. }
  1519. if CreateBy != "" {
  1520. where = where + " and CreateBy like '%" + CreateBy + "%'"
  1521. }
  1522. if ModifiedOn != "" {
  1523. where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
  1524. }
  1525. if ModifiedUserId != "" {
  1526. where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
  1527. }
  1528. if ModifiedBy != "" {
  1529. where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
  1530. }
  1531. if CreateOn != "" {
  1532. dates := strings.Split(CreateOn, ",")
  1533. if len(dates) == 2 {
  1534. minDate := dates[0]
  1535. maxDate := dates[1]
  1536. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  1537. }
  1538. }
  1539. where = where + " and Type in (1, 3)"
  1540. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  1541. var list []suppliercertsub.Tmp_OilSupplierCertSub
  1542. total := svc.GetMyPagingEntitiesWithOrderBytbl(TmpOilSupplierCertSubName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  1543. var datainfo DataInfo
  1544. datainfo.Items = list
  1545. datainfo.CurrentItemCount = total
  1546. datainfo.PageIndex = page.CurrentPage
  1547. datainfo.ItemsPerPage = page.Size
  1548. this.Data["json"] = &datainfo
  1549. this.ServeJSON()
  1550. }
  1551. // @Title 删除不符合的的准入项
  1552. // @Description get user by token
  1553. // @Success 200 {object} []suppliercertsub.OilSupplierCertSub
  1554. // @router /deltmpsuppliercertsub [get]
  1555. func (this *OilGoodsAptitudeController) DelTmpSupplierCertSub() {
  1556. var err error
  1557. session := utils.DBE.NewSession()
  1558. session.Begin()
  1559. defer session.Close()
  1560. svc := goodsaptitude.GetOilGoodsAptitudeSession(session)
  1561. var supplierCertSubList []suppliercertsub.Tmp_OilSupplierCertSub
  1562. wheredel := "1=1 and SupplierTypeCode = '01'"
  1563. svc.GetEntitysByWhere(TmpOilSupplierCertSubName, wheredel, &supplierCertSubList)
  1564. var errinfo ErrorInfo
  1565. for _, item := range supplierCertSubList {
  1566. where := "Id = " + strconv.Itoa(item.Id)
  1567. err = svc.DeleteEntityBytbl(OilSupplierCertSubName, where)
  1568. if err != nil {
  1569. session.Rollback()
  1570. errinfo.Code = -1
  1571. errinfo.Message = "删除失败!"
  1572. this.Data["json"] = &errinfo
  1573. this.ServeJSON()
  1574. }
  1575. }
  1576. for _, item := range supplierCertSubList {
  1577. where := "Id = " + strconv.Itoa(item.Id)
  1578. err = svc.DeleteEntityBytbl(TmpOilSupplierCertSubName, where)
  1579. }
  1580. if err == nil {
  1581. session.Commit()
  1582. errinfo.Code = 0
  1583. errinfo.Message = "删除成功!"
  1584. this.Data["json"] = &errinfo
  1585. this.ServeJSON()
  1586. } else {
  1587. session.Rollback()
  1588. errinfo.Code = -1
  1589. errinfo.Message = "删除失败!"
  1590. this.Data["json"] = &errinfo
  1591. this.ServeJSON()
  1592. }
  1593. }
  1594. // @Title 修改资质后找出不符合的准入
  1595. // @Description 修改实体
  1596. // @Success 200 {object} controllers.Request
  1597. // @router /findinconformity [post]
  1598. func (this *OilGoodsAptitudeController) FindInconformity() {
  1599. var errinfo ErrorInfo
  1600. var err error
  1601. var model goodsaptitude.OilGoodsAptitude_2
  1602. var companygoodslist []suppliercertsub.OilSupplierCertSub
  1603. var companygood suppliercertsub.OilSupplierCertSub
  1604. var SurplusList1 []supplierfile.FileList
  1605. var SurplusList2 []supplierfile.FileList
  1606. var supfilemodel []supplierfile.OilSupplierFile
  1607. var supfilemodel01 []supplierfile.OilSupplierFile
  1608. var supfilemodel02 []supplierfile.OilSupplierFile
  1609. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  1610. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  1611. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  1612. var jsonBlob = this.Ctx.Input.RequestBody
  1613. json.Unmarshal(jsonBlob, &model)
  1614. Code := model.Code
  1615. where := " Code ='" + Code + "' and Type in ('1','3') and SupplierTypeCode = '01'"
  1616. svc.FindGoodsByCode("OilSupplierCertSub", where, &companygoodslist)
  1617. SurplusList1 = filesvc.GetGoodsNeedFileList(strconv.Itoa(model.ClassId), "1")
  1618. SurplusList2 = filesvc.GetGoodsNeedFileList(strconv.Itoa(model.ClassId), "2")
  1619. for _, CertSub := range companygoodslist {
  1620. companygood = CertSub
  1621. wherecompany := " SupplierId =" + strconv.Itoa(CertSub.SupplierId)
  1622. svc.FindFileByCompany("OilSupplierFile", wherecompany, &supfilemodel)
  1623. if len(supfilemodel) < 1 {
  1624. _, err = svc.InsertEntityBytbl(""+TmpOilSupplierCertSubName, &companygood)
  1625. } else {
  1626. var tmplist1 []suppliercertsub.Tmp_OilSupplierCertSub
  1627. wherecompany = " Id =" + strconv.Itoa(CertSub.Id)
  1628. svc.FindFileByCompany("tmp_OilSupplierCertSub", wherecompany, &tmplist1)
  1629. if len(tmplist1) < 1 {
  1630. wherecompany = " SupplierId ='" + strconv.Itoa(CertSub.SupplierId) + "' and IsManuf in ('0','1')"
  1631. svc.FindFileByCompany("OilSupplierFile", wherecompany, &supfilemodel01)
  1632. var File01 string
  1633. for _, Filesub := range supfilemodel01 {
  1634. File01 = File01 + Filesub.NeedFileType + ","
  1635. }
  1636. for _, Filesub := range SurplusList1 {
  1637. var supplierModel supplier.OilSupplier
  1638. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  1639. svcSupplier.GetEntityById(strconv.Itoa(CertSub.SupplierId), &supplierModel)
  1640. //三证合一或五证合一不需要的字段
  1641. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  1642. File01 = mergerCertSkipField + File01
  1643. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(File01, Filesub.FileName+",") { //三证合一或五证合一了
  1644. continue
  1645. }
  1646. if strings.Contains(File01, Filesub.FileName+",") {
  1647. continue
  1648. }
  1649. _, err = svc.InsertEntityBytbl(""+TmpOilSupplierCertSubName, &companygood)
  1650. break
  1651. }
  1652. }
  1653. var tmplist2 []suppliercertsub.Tmp_OilSupplierCertSub
  1654. wherecompany = " Id =" + strconv.Itoa(CertSub.Id)
  1655. svc.FindFileByCompany("tmp_OilSupplierCertSub", wherecompany, &tmplist2)
  1656. if len(tmplist2) < 1 {
  1657. wherecompany = " SupplierId ='" + strconv.Itoa(CertSub.SupplierId) + "' and IsManuf in ('0','2')"
  1658. svc.FindFileByCompany("OilSupplierFile", wherecompany, &supfilemodel02)
  1659. var File02 string
  1660. for _, Filesub := range supfilemodel02 {
  1661. File02 = File02 + Filesub.NeedFileType + ","
  1662. }
  1663. for _, Filesub := range SurplusList2 {
  1664. var supplierModel supplier.OilSupplier
  1665. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  1666. svcSupplier.GetEntityById(strconv.Itoa(CertSub.SupplierId), &supplierModel)
  1667. //三证合一或五证合一不需要的字段
  1668. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  1669. File02 = mergerCertSkipField + File02
  1670. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(File02, Filesub.FileName+",") { //三证合一或五证合一了
  1671. continue
  1672. }
  1673. if strings.Contains(File02, Filesub.FileName+",") {
  1674. continue
  1675. }
  1676. _, err = svc.InsertEntityBytbl(""+TmpOilSupplierCertSubName, &companygood)
  1677. break
  1678. }
  1679. }
  1680. }
  1681. var certsub suppliercertsub.OilSupplierCertSub
  1682. certsub.GoodsLevel = model.GoodsLevel
  1683. cols := []string{"GoodsLevel"}
  1684. where := "Id=" + strconv.Itoa(CertSub.Id)
  1685. svc.UpdateEntityBywheretbl(OilSupplierCertSubName, &certsub, cols, where)
  1686. }
  1687. if err == nil {
  1688. errinfo.Message = "已拉取缺失资质列表!"
  1689. errinfo.Code = 0
  1690. this.Data["json"] = &errinfo
  1691. this.ServeJSON()
  1692. } else {
  1693. errinfo.Message = "拉取列表失败!" + utils.AlertProcess(err.Error())
  1694. errinfo.Code = -1
  1695. this.Data["json"] = &errinfo
  1696. this.ServeJSON()
  1697. }
  1698. }