2
3

goodsaptitude.go 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. package oilsupplier
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/tealeg/xlsx"
  6. "os"
  7. "reflect"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "dashoo.cn/backend/api/business/oilsupplier/goodsaptitudeclass"
  12. "dashoo.cn/backend/api/business/items"
  13. "dashoo.cn/backend/api/business/baseUser"
  14. "dashoo.cn/backend/api/business/oilsupplier/goodsaptitude"
  15. . "dashoo.cn/backend/api/controllers"
  16. "dashoo.cn/business2/userRole"
  17. "dashoo.cn/utils"
  18. . "github.com/linxGnu/goseaweedfs"
  19. )
  20. type OilGoodsAptitudeController struct {
  21. BaseController
  22. }
  23. // @Title 获取列表
  24. // @Description get user by token
  25. // @Success 200 {object} []goodsaptitude.OilGoodsAptitude
  26. // @router /list [get]
  27. func (this *OilGoodsAptitudeController) GetEntityList() {
  28. //获取分页信息
  29. page := this.GetPageInfoForm()
  30. where := " 1=1 "
  31. orderby := "Code"
  32. asc := true
  33. Order := this.GetString("Order")
  34. Prop := this.GetString("Prop")
  35. if Order != "" && Prop != "" {
  36. orderby = Prop
  37. if Order == "asc" {
  38. asc = true
  39. } else {
  40. asc = false
  41. }
  42. }
  43. Edition := this.GetString("Edition")
  44. CreateOn := this.GetString("CreateOn")
  45. Code := this.GetString("Code")
  46. Name := this.GetString("Name")
  47. BigClassName := this.GetString("BigClassName")
  48. BigClassCode := this.GetString("BigClassCode")
  49. MiddleClassName := this.GetString("MiddleClassName")
  50. SmallClassName := this.GetString("SmallClassName")
  51. GoodsName := this.GetString("GoodsName")
  52. GoodsLevel := this.GetString("GoodsLevel")
  53. GoodsDesc := this.GetString("GoodsDesc")
  54. Standard := this.GetString("Standard")
  55. CompanyType := this.GetString("CompanyType")
  56. if Edition != "" {
  57. where = where + " and Edition = '" + Edition + "'"
  58. }
  59. if Code != "" {
  60. where = where + " and Code like '%" + Code + "%'"
  61. }
  62. if Name != "" {
  63. where = where + " and Name like '%" + Name + "%'"
  64. }
  65. if BigClassName != "" {
  66. where = where + " and Name1 like '%" + BigClassName + "%'"
  67. }
  68. if BigClassCode != "" {
  69. where = where + " and Code1 like '%" + BigClassCode + "%'"
  70. }
  71. if MiddleClassName != "" {
  72. where = where + " and Name2 like '%" + MiddleClassName + "%'"
  73. }
  74. if SmallClassName != "" {
  75. where = where + " and Name3 '%" + SmallClassName + "%'"
  76. }
  77. if GoodsName != "" {
  78. where = where + " and Name4 like '%" + GoodsName + "%'"
  79. }
  80. if GoodsLevel != "" {
  81. where = where + " and GoodsLevel like '%" + GoodsLevel + "%'"
  82. }
  83. if GoodsDesc != "" {
  84. where = where + " and GoodsDesc like '%" + GoodsDesc + "%'"
  85. }
  86. if Standard != "" {
  87. where = where + " and Standard '%" + Standard + "%'"
  88. }
  89. if CompanyType != "" {
  90. where = where + " and CompanyType '%" + CompanyType + "%'"
  91. }
  92. if CreateOn != "" {
  93. dates := strings.Split(CreateOn, ",")
  94. if len(dates) == 2 {
  95. minDate := dates[0]
  96. maxDate := dates[1]
  97. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  98. }
  99. }
  100. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  101. var list []goodsaptitude.OilGoodsAptitudeView
  102. total := svc.GetMyPagingEntitiesWithOrderBytbl(OilGoodsAptDetailViewName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  103. var datainfo DataInfo
  104. datainfo.Items = list
  105. datainfo.CurrentItemCount = total
  106. datainfo.PageIndex = page.CurrentPage
  107. datainfo.ItemsPerPage = page.Size
  108. this.Data["json"] = &datainfo
  109. this.ServeJSON()
  110. }
  111. // @Title 获取列表2019版本
  112. // @Description
  113. // @Success 200 {object}
  114. // @router /list_2019 [get]
  115. func (this *OilGoodsAptitudeController) GetEntityList_2019() {
  116. //获取分页信息
  117. page := this.GetPageInfoForm()
  118. where := " 1=1 "
  119. orderby := "Code"
  120. asc := true
  121. Order := this.GetString("Order")
  122. Prop := this.GetString("Prop")
  123. if Order != "" && Prop != "" {
  124. orderby = Prop
  125. if Order == "asc" {
  126. asc = true
  127. } else {
  128. asc = false
  129. }
  130. }
  131. Edition := this.GetString("Edition")
  132. Code := this.GetString("Code")
  133. Name := this.GetString("Name")
  134. if Edition != "" {
  135. where = where + " and a.Edition = '" + Edition + "'"
  136. }
  137. if Code != "" {
  138. where = where + " and b.Code like '%" + Code + "%'"
  139. }
  140. if Name != "" {
  141. where = where + " and b.Name like '%" + Name + "%'"
  142. }
  143. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  144. var list []goodsaptitude.OilGoodsAptitude_2
  145. total := svc.GetList_2019(OilGoodsAptitudeName, OilGoodsAptitudeClassName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  146. var datainfo DataInfo
  147. datainfo.Items = list
  148. datainfo.CurrentItemCount = total
  149. datainfo.PageIndex = page.CurrentPage
  150. datainfo.ItemsPerPage = page.Size
  151. this.Data["json"] = &datainfo
  152. this.ServeJSON()
  153. }
  154. // @Title 获取字典列表
  155. // @Description get user by token
  156. // @Success 200 {object} map[string]interface{}
  157. // @router /dictlist [get]
  158. func (this *OilGoodsAptitudeController) GetDictList() {
  159. dictList := make(map[string]interface{})
  160. dictSvc := items.GetItemsService(utils.DBE)
  161. userSvc := baseUser.GetBaseUserService(utils.DBE)
  162. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  163. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", "")
  164. var userEntity userRole.Base_User
  165. userSvc.GetEntityById(this.User.Id, &userEntity)
  166. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId("", userEntity.Departmentid)
  167. dictList["AuditStep"] = dictSvc.GetKeyValueItems("AuditStep", this.User.AccCode)
  168. //var dictCustomer []svccustomer.Customer
  169. //customerSvc.GetEntitysByWhere("" + CustomerName, "", &dictCustomer)
  170. //dictList["EntrustCorp"] = &dictCustomer
  171. var datainfo DataInfo
  172. datainfo.Items = dictList
  173. this.Data["json"] = &datainfo
  174. this.ServeJSON()
  175. }
  176. // @Title 获取实体
  177. // @Description 获取实体
  178. // @Success 200 {object} goodsaptitude.OilGoodsAptitude
  179. // @router /get/:id [get]
  180. func (this *OilGoodsAptitudeController) GetEntity() {
  181. Id := this.Ctx.Input.Param(":id")
  182. var model goodsaptitude.OilGoodsAptitudeView
  183. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  184. //svc.GetEntityByIdBytbl(""+OilGoodsAptitudeName, Id, &model)
  185. where := " Id =" + Id
  186. svc.GetEntityByWhere(OilGoodsAptDetailViewName, where, &model)
  187. this.Data["json"] = &model
  188. this.ServeJSON()
  189. }
  190. // @Title 获取实体
  191. // @Description 获取实体
  192. // @Success 200 {object}
  193. // @router /get_2019/:id [get]
  194. func (this *OilGoodsAptitudeController) GetEntity_2019() {
  195. Id := this.Ctx.Input.Param(":id")
  196. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  197. var tempMap []map[string]string
  198. 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,
  199. a.F11,a.F12,a.F13,a.F14,a.F15,a.F16,a.F17,a.F18,a.F19,a.F20,
  200. a.F21,a.F22,a.F23,a.F24,a.F25,a.F26,a.F27,a.F28,a.F29,a.F30,
  201. a.F31,a.F32,a.F33,a.F34,a.F35,a.F36,a.F37,a.F38,a.F39,a.F40,
  202. a.F41,a.F42,a.F43,a.F44,a.F45,a.F46,b.Code, b.Name `
  203. sql += ` from ` + OilGoodsAptitudeName + ` a `
  204. sql += ` left join ` + OilGoodsAptitudeClassName + " b on b.Id = a.ClassId"
  205. sql += ` where a.Id='` + Id + `'`
  206. tempMap, _ = svc.DBE.QueryString(sql)
  207. this.Data["json"] = &tempMap
  208. this.ServeJSON()
  209. }
  210. // @Title 添加
  211. // @Description 新增
  212. // @Success 200 {object} controllers.Request
  213. // @router /add/:id [post]
  214. func (this *OilGoodsAptitudeController) AddEntity() {
  215. classId := this.Ctx.Input.Param(":id")
  216. var model goodsaptitude.OilGoodsAptitude
  217. var jsonBlob = this.Ctx.Input.RequestBody
  218. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  219. json.Unmarshal(jsonBlob, &model)
  220. model.CreateOn = time.Now()
  221. model.CreateBy = this.User.Realname
  222. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  223. model.ClassId, _ = strconv.Atoi(classId)
  224. //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  225. _, err := svc.InsertEntityBytbl(""+OilGoodsAptitudeName, &model)
  226. var errinfo ErrorDataInfo
  227. if err == nil {
  228. //新增
  229. errinfo.Message = "添加成功!"
  230. errinfo.Code = 0
  231. errinfo.Item = model.Id
  232. this.Data["json"] = &errinfo
  233. this.ServeJSON()
  234. } else {
  235. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  236. errinfo.Code = -1
  237. this.Data["json"] = &errinfo
  238. this.ServeJSON()
  239. }
  240. }
  241. // @Title 添加
  242. // @Description 新增
  243. // @Success 200 {object} controllers.Request
  244. // @router /add_2019 [post]
  245. func (this *OilGoodsAptitudeController) AddEntity_2019() {
  246. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  247. var model goodsaptitudeclass.OilGoodsAptitudeClass
  248. var jsonBlob = this.Ctx.Input.RequestBody
  249. json.Unmarshal(jsonBlob, &model)
  250. model.ParentId = -1
  251. model.Edition = "2"
  252. model.CreateOn = time.Now()
  253. model.CreateBy = this.User.Realname
  254. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  255. _, err := svc.InsertEntityBytbl(""+OilGoodsAptitudeClassName, &model)
  256. var model2 goodsaptitude.OilGoodsAptitude
  257. json.Unmarshal(jsonBlob, &model2)
  258. model2.ClassId = model.Id
  259. model2.Edition = "2"
  260. model2.CreateOn = time.Now()
  261. model2.CreateBy = this.User.Realname
  262. model2.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  263. _, err = svc.InsertEntityBytbl(""+OilGoodsAptitudeName, &model2)
  264. var errinfo ErrorDataInfo
  265. if err == nil {
  266. //新增
  267. errinfo.Message = "添加成功!"
  268. errinfo.Code = 0
  269. errinfo.Item = model2.Id
  270. this.Data["json"] = &errinfo
  271. this.ServeJSON()
  272. } else {
  273. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  274. errinfo.Code = -1
  275. this.Data["json"] = &errinfo
  276. this.ServeJSON()
  277. }
  278. }
  279. // @Title 修改实体
  280. // @Description 修改实体
  281. // @Success 200 {object} controllers.Request
  282. // @router /update/:id [post]
  283. func (this *OilGoodsAptitudeController) UpdateEntity() {
  284. id := this.Ctx.Input.Param(":id")
  285. var errinfo ErrorInfo
  286. if id == "" {
  287. errinfo.Message = "操作失败!请求信息不完整"
  288. errinfo.Code = -2
  289. this.Data["json"] = &errinfo
  290. this.ServeJSON()
  291. return
  292. }
  293. var model goodsaptitude.OilGoodsAptitude
  294. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  295. var jsonBlob = this.Ctx.Input.RequestBody
  296. json.Unmarshal(jsonBlob, &model)
  297. model.ModifiedOn = time.Now()
  298. model.ModifiedBy = this.User.Realname
  299. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  300. cols := []string{
  301. "Id",
  302. "Code",
  303. "Name",
  304. "BigClassName",
  305. "MiddleClassName",
  306. "SmallClassName",
  307. "GoodsName",
  308. "GoodsLevel",
  309. "GoodsDesc",
  310. "Standard",
  311. "CompanyType",
  312. "F01",
  313. "F02",
  314. "F03",
  315. "F04",
  316. "F05",
  317. "F06",
  318. "F07",
  319. "F08",
  320. "F09",
  321. "F10",
  322. "F11",
  323. "F12",
  324. "F13",
  325. "F14",
  326. "F15",
  327. "F16",
  328. "F17",
  329. "F18",
  330. "F19",
  331. "F20",
  332. "F21",
  333. "F22",
  334. "F23",
  335. "F24",
  336. "F25",
  337. "F26",
  338. "F27",
  339. "F28",
  340. "F29",
  341. "F30",
  342. "F31",
  343. "F32",
  344. "F33",
  345. "F34",
  346. "F35",
  347. "F36",
  348. "F37",
  349. "F38",
  350. "F39",
  351. "F40",
  352. "F41",
  353. "F42",
  354. "F43",
  355. "F44",
  356. "F45",
  357. "F46",
  358. "Remark",
  359. "DeletionStateCode",
  360. "CreateOn",
  361. "CreateUserId",
  362. "CreateBy",
  363. "ModifiedOn",
  364. "ModifiedUserId",
  365. "ModifiedBy",
  366. }
  367. err := svc.UpdateEntityBytbl(""+OilGoodsAptitudeName, id, &model, cols)
  368. if err == nil {
  369. errinfo.Message = "修改成功!"
  370. errinfo.Code = 0
  371. this.Data["json"] = &errinfo
  372. this.ServeJSON()
  373. } else {
  374. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  375. errinfo.Code = -1
  376. this.Data["json"] = &errinfo
  377. this.ServeJSON()
  378. }
  379. }
  380. // @Title 修改实体
  381. // @Description 修改实体
  382. // @Success 200 {object} controllers.Request
  383. // @router /update_2019/:id [post]
  384. func (this *OilGoodsAptitudeController) UpdateEntity_2019() {
  385. id := this.Ctx.Input.Param(":id")
  386. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  387. var errinfo ErrorInfo
  388. if id == "" {
  389. errinfo.Message = "操作失败!请求信息不完整"
  390. errinfo.Code = -2
  391. this.Data["json"] = &errinfo
  392. this.ServeJSON()
  393. return
  394. }
  395. var model goodsaptitude.OilGoodsAptitude
  396. var jsonBlob = this.Ctx.Input.RequestBody
  397. json.Unmarshal(jsonBlob, &model)
  398. model.ModifiedOn = time.Now()
  399. model.ModifiedBy = this.User.Realname
  400. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  401. cols := []string{
  402. "F01",
  403. "F02",
  404. "F03",
  405. "F04",
  406. "F05",
  407. "F06",
  408. "F07",
  409. "F08",
  410. "F09",
  411. "F10",
  412. "F11",
  413. "F12",
  414. "F13",
  415. "F14",
  416. "F15",
  417. "F16",
  418. "F17",
  419. "F18",
  420. "F19",
  421. "F20",
  422. "F21",
  423. "F22",
  424. "F23",
  425. "F24",
  426. "F25",
  427. "F26",
  428. "F27",
  429. "F28",
  430. "F29",
  431. "F30",
  432. "F31",
  433. "F32",
  434. "F33",
  435. "F34",
  436. "F35",
  437. "F36",
  438. "F37",
  439. "F38",
  440. "F39",
  441. "F40",
  442. "F41",
  443. "F42",
  444. "F43",
  445. "F44",
  446. "F45",
  447. "F46",
  448. "ModifiedOn",
  449. "ModifiedUserId",
  450. "ModifiedBy",
  451. }
  452. err := svc.UpdateEntityBytbl(""+OilGoodsAptitudeName, id, &model, cols)
  453. var model2 goodsaptitudeclass.OilGoodsAptitudeClass
  454. json.Unmarshal(jsonBlob, &model2)
  455. model2.ModifiedOn = time.Now()
  456. model2.ModifiedBy = this.User.Realname
  457. model2.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  458. cols2 := []string{
  459. "Code",
  460. "Name",
  461. "ModifiedOn",
  462. "ModifiedUserId",
  463. "ModifiedBy",
  464. }
  465. err = svc.UpdateEntityBytbl(""+OilGoodsAptitudeClassName, model.ClassId, &model2, cols2)
  466. if err == nil {
  467. errinfo.Message = "修改成功!"
  468. errinfo.Code = 0
  469. this.Data["json"] = &errinfo
  470. this.ServeJSON()
  471. } else {
  472. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  473. errinfo.Code = -1
  474. this.Data["json"] = &errinfo
  475. this.ServeJSON()
  476. }
  477. }
  478. // @Title 修改实体
  479. // @Description 修改实体
  480. // @Success 200 {object} controllers.Request
  481. // @router /updatecode/:id [post]
  482. func (this *OilGoodsAptitudeController) UpdateCodeEntity() {
  483. var errinfo ErrorInfo
  484. var err error
  485. id := this.Ctx.Input.Param(":id")
  486. if id == "" {
  487. errinfo.Message = "操作失败!请求信息不完整"
  488. errinfo.Code = -2
  489. this.Data["json"] = &errinfo
  490. this.ServeJSON()
  491. return
  492. }
  493. var classall goodsaptitude.OilGoodsAptitudeClassView
  494. var model goodsaptitudeclass.OilGoodsAptitudeClass
  495. var classmodel []goodsaptitudeclass.OilGoodsAptitudeClass
  496. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  497. var jsonBlob = this.Ctx.Input.RequestBody
  498. json.Unmarshal(jsonBlob, &classall)
  499. model.ModifiedOn = time.Now()
  500. model.ModifiedBy = this.User.Realname
  501. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  502. colsName := []string{"Name"}
  503. colsCode := []string{"Code"}
  504. //svc.GetEntityById(id, &model)
  505. if classall.Name1 != "" {
  506. where := " Name = '" + classall.Name1 + "' and Id <> " + utils.ToStr(classall.Id1)
  507. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  508. if len(classmodel) > 0 {
  509. errinfo.Message = "大类名称已存在,请重新添加!"
  510. errinfo.Code = -1
  511. this.Data["json"] = &errinfo
  512. this.ServeJSON()
  513. return
  514. } else {
  515. model.Name = classall.Name1
  516. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id1, &model, colsName)
  517. }
  518. }
  519. if classall.Name2 != "" {
  520. where := " Name = '" + classall.Name2 + "' and Id <> " + utils.ToStr(classall.Id2)
  521. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  522. if len(classmodel) > 0 {
  523. errinfo.Message = "中类名称已存在,请重新添加!"
  524. errinfo.Code = -1
  525. this.Data["json"] = &errinfo
  526. this.ServeJSON()
  527. return
  528. } else {
  529. model.Name = classall.Name2
  530. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id2, &model, colsName)
  531. }
  532. }
  533. if classall.Name3 != "" {
  534. where := " Name = '" + classall.Name3 + "' and Id <> " + utils.ToStr(classall.Id3)
  535. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  536. if len(classmodel) > 0 {
  537. errinfo.Message = "小类名称已存在,请重新添加!"
  538. errinfo.Code = -1
  539. this.Data["json"] = &errinfo
  540. this.ServeJSON()
  541. return
  542. } else {
  543. model.Name = classall.Name3
  544. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id3, &model, colsName)
  545. }
  546. }
  547. if classall.Name4 != "" {
  548. where := " Name = '" + classall.Name4 + "' and Id <> " + utils.ToStr(classall.Id4)
  549. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  550. if len(classmodel) > 0 {
  551. errinfo.Message = "品名已存在,请重新添加!"
  552. errinfo.Code = -1
  553. this.Data["json"] = &errinfo
  554. this.ServeJSON()
  555. return
  556. } else {
  557. model.Name = classall.Name4
  558. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id4, &model, colsName)
  559. }
  560. }
  561. if classall.Code1 != "" {
  562. where := " Code = " + classall.Code1 + " and Id <> " + utils.ToStr(classall.Id1)
  563. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  564. if len(classmodel) > 0 {
  565. errinfo.Message = "大类编码已存在,请重新添加!"
  566. errinfo.Code = -1
  567. this.Data["json"] = &errinfo
  568. this.ServeJSON()
  569. return
  570. } else {
  571. model.Code = classall.Code1
  572. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id1, &model, colsCode)
  573. }
  574. }
  575. if classall.Code2 != "" {
  576. where := " Code = " + classall.Code2 + " and Id <> " + utils.ToStr(classall.Id2)
  577. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  578. if len(classmodel) > 0 {
  579. errinfo.Message = "中类编码已存在,请重新添加!"
  580. errinfo.Code = -1
  581. this.Data["json"] = &errinfo
  582. this.ServeJSON()
  583. return
  584. } else {
  585. model.Code = classall.Code2
  586. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id2, &model, colsCode)
  587. }
  588. }
  589. if classall.Code3 != "" {
  590. where := " Code = " + classall.Code3 + " and Id <> " + utils.ToStr(classall.Id3)
  591. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  592. if len(classmodel) > 0 {
  593. errinfo.Message = "小类编码已存在,请重新添加!"
  594. errinfo.Code = -1
  595. this.Data["json"] = &errinfo
  596. this.ServeJSON()
  597. return
  598. } else {
  599. model.Code = classall.Code3
  600. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id3, &model, colsCode)
  601. }
  602. }
  603. if classall.Code4 != "" {
  604. where := " Code = " + classall.Code4 + " and Id <> " + utils.ToStr(classall.Id4)
  605. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  606. if len(classmodel) > 0 {
  607. errinfo.Message = "品名编码已存在,请重新添加!"
  608. errinfo.Code = -1
  609. this.Data["json"] = &errinfo
  610. this.ServeJSON()
  611. return
  612. } else {
  613. model.Code = classall.Code4
  614. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id4, &model, colsCode)
  615. }
  616. }
  617. if err == nil {
  618. errinfo.Message = "修改成功!"
  619. errinfo.Code = 0
  620. this.Data["json"] = &errinfo
  621. this.ServeJSON()
  622. } else {
  623. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  624. errinfo.Code = -1
  625. this.Data["json"] = &errinfo
  626. this.ServeJSON()
  627. }
  628. }
  629. // @Title 删除单条信息
  630. // @Description
  631. // @Success 200 {object} ErrorInfo
  632. // @Failure 403 :id 为空
  633. // @router /delete/:Id [delete]
  634. func (this *OilGoodsAptitudeController) DeleteEntity() {
  635. Id := this.Ctx.Input.Param(":Id")
  636. var errinfo ErrorInfo
  637. if Id == "" {
  638. errinfo.Message = "操作失败!请求信息不完整"
  639. errinfo.Code = -2
  640. this.Data["json"] = &errinfo
  641. this.ServeJSON()
  642. return
  643. }
  644. var model goodsaptitude.OilGoodsAptitude
  645. var entityempty goodsaptitude.OilGoodsAptitude
  646. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  647. opdesc := "删除-" + Id
  648. err := svc.DeleteOperationAndWriteLogBytbl(""+OilGoodsAptitudeName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "钻井日报")
  649. if err == nil {
  650. errinfo.Message = "删除成功"
  651. errinfo.Code = 0
  652. this.Data["json"] = &errinfo
  653. this.ServeJSON()
  654. } else {
  655. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  656. errinfo.Code = -1
  657. this.Data["json"] = &errinfo
  658. this.ServeJSON()
  659. }
  660. }
  661. // @Title get 查询
  662. // @Description get SampleType by token
  663. // @Success 200 {object} sampletype.SampleType
  664. // @router /goodsparentlist/:name [get]
  665. func (this *OilGoodsAptitudeController) GoodsParentList() {
  666. Name := this.Ctx.Input.Param(":name")
  667. if Name != "" {
  668. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  669. where1 := "1=1"
  670. where1 += " AND Name LIKE '%" + Name + "%' OR Code LIKE '" + Name + "%' "
  671. sqlStr := "SELECT Id, Code, Name, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass " +
  672. "WHERE " + where1 + " AND Edition='1' AND DeletionStateCode = 0 ORDER BY Code"
  673. list, _ := svc.DBE.QueryString(sqlStr)
  674. /*
  675. sql := "SELECT Id, Code, Name, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass " +
  676. "WHERE DeletionStateCode = 0 AND " + where1 + " OR Id = (" + sqlStr + ")" +" ORDER BY Code"
  677. list, _ := svc.DBE.QueryString(sql)*/
  678. var datainfo DataInfo
  679. datainfo.Items = list
  680. this.Data["json"] = &datainfo
  681. this.ServeJSON()
  682. }
  683. }
  684. // @Title get 获取子类
  685. // @Description get SampleType by token
  686. // @Success 200 {object} sampletype.SampleType
  687. // @router /goodschildlist/:id [get]
  688. func (this *OilGoodsAptitudeController) GoodsChildList() {
  689. ParentId := this.Ctx.Input.Param(":id")
  690. 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"
  691. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  692. list, _ := svc.DBE.QueryString(sqlStr)
  693. var datainfo DataInfo
  694. datainfo.Items = list
  695. this.Data["json"] = &datainfo
  696. this.ServeJSON()
  697. }
  698. // @Title get 获取子类
  699. // @Description get SampleType by token
  700. // @Success 200 {object} sampletype.SampleType
  701. // @router /goodschildlistbypid/:parentid [get]
  702. func (this *OilGoodsAptitudeController) GoodsChildLisByParentId() {
  703. ParentId := this.Ctx.Input.Param(":parentid")
  704. sqlStr := "SELECT o.Id, o.`Code`, o.`Name`, concat(o.Code, ' ', o.Name) as CodeName, o.ParentId, g.GoodsLevel," +
  705. " (CASE WHEN length(Code)>=8 THEN '1' ELSE '0' END) as Leaf FROM OilGoodsAptitudeClass o " +
  706. " LEFT JOIN `OilGoodsAptitude` g ON (g.ClassId = o.Id)" +
  707. " WHERE o.ParentId = '" + ParentId + "' AND o.Edition='1' AND o.DeletionStateCode = 0 order by o.Code"
  708. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  709. list, _ := svc.DBE.QueryString(sqlStr)
  710. var datainfo DataInfo
  711. datainfo.Items = list
  712. this.Data["json"] = &datainfo
  713. this.ServeJSON()
  714. }
  715. // @Title get 导出ex
  716. // @Description get SampleType by token
  717. // @Success 200 {object} sampletype.SampleType
  718. // @router /exportexcelall [get]
  719. func (this *OilGoodsAptitudeController) ExportExcelAll() {
  720. //获取分页信息
  721. //page := this.GetPageInfoForm()
  722. where := " 1=1 "
  723. orderby := "Code"
  724. asc := true
  725. Order := this.GetString("Order")
  726. Prop := this.GetString("Prop")
  727. if Order != "" && Prop != "" {
  728. orderby = Prop
  729. if Order == "asc" {
  730. asc = true
  731. } else {
  732. asc = false
  733. }
  734. }
  735. Edition := this.GetString("Edition")
  736. if Edition != "" {
  737. where = where + " and Edition = '" + Edition + "'"
  738. }
  739. t := time.Now()
  740. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  741. var list []goodsaptitude.OilGoodsAptitudeView
  742. svc.GetMyPagingEntitiesWithOrderBytbl(OilGoodsAptDetailViewName, 0, 0, orderby, asc, &list, where)
  743. var title []string
  744. filetitle := "物资类"
  745. //自定义显示列
  746. showcolumnarr := this.GetString("showcolumnarr")
  747. showcolumnnamearr := this.GetString("showcolumnnamearr")
  748. titlestring := showcolumnnamearr
  749. title = strings.Split(titlestring, ",")
  750. f := xlsx.NewFile()
  751. sheet, _ := f.AddSheet(filetitle)
  752. //rowhead := sheet.AddRow()
  753. //rowhead.WriteSlice(&title, -1)
  754. cellname := strings.Split(showcolumnarr, ",")
  755. row := sheet.AddRow()
  756. row.WriteSlice(&cellname, -1)
  757. for _, item := range list {
  758. var enumModel goodsaptitude.OilGoodsAptitudeView
  759. tmpModel := &item
  760. enumModel = *tmpModel
  761. immumodel := reflect.ValueOf(&enumModel)
  762. elem := immumodel.Elem()
  763. row := sheet.AddRow()
  764. for _, name := range title {
  765. cell := row.AddCell()
  766. if strings.HasPrefix(name, "F") {
  767. var val = elem.FieldByName(name).String()
  768. if val == "1" {
  769. cell.Value = "是"
  770. } else {
  771. cell.Value = ""
  772. }
  773. } else {
  774. cell.Value = elem.FieldByName(name).String()
  775. }
  776. }
  777. }
  778. for c, cl := 0, len(sheet.Cols); c < cl; c++ {
  779. sheet.Cols[c].Width = 20
  780. }
  781. //this.SaveSampleXlsx(filetitle, title, showcolumnarr, list, f)
  782. dir := "static/file/excel/report/" + this.GetAccode()
  783. SaveDirectory(dir)
  784. path := dir + "/" + utils.TimeFormat(time.Now(), "200612") + filetitle + ".xlsx"
  785. f.Save(path)
  786. var sw *Seaweed
  787. var filer []string
  788. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  789. filer = []string{_filer}
  790. }
  791. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  792. _, _, fID, _ := sw.UploadFile(path, "", "")
  793. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  794. os.Remove(path)
  795. fmt.Println("==retDocWatermarkUrl==", retDocUrl)
  796. this.Data["json"] = retDocUrl
  797. this.ServeJSON()
  798. elapsed := time.Since(t)
  799. fmt.Println(elapsed)
  800. }
  801. // @Title get 导出ex
  802. // @Description get SampleType by token
  803. // @Success 200 {object} sampletype.SampleType
  804. // @router /exportexcelall2019 [get]
  805. func (this *OilGoodsAptitudeController) ExportExcelAll2019() {
  806. //获取分页信息
  807. //page := this.GetPageInfoForm()
  808. where := " 1=1 "
  809. orderby := "Code"
  810. asc := true
  811. Order := this.GetString("Order")
  812. Prop := this.GetString("Prop")
  813. if Order != "" && Prop != "" {
  814. orderby = Prop
  815. if Order == "asc" {
  816. asc = true
  817. } else {
  818. asc = false
  819. }
  820. }
  821. Edition := this.GetString("Edition")
  822. if Edition != "" {
  823. where = where + " and a.Edition = '" + Edition + "'"
  824. }
  825. t := time.Now()
  826. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  827. var list []goodsaptitude.OilGoodsAptitude_2
  828. svc.GetList_2019(OilGoodsAptitudeName, OilGoodsAptitudeClassName, 0, 0, orderby, asc, &list, where)
  829. var title []string
  830. filetitle := "物资类(顶级)"
  831. //自定义显示列
  832. showcolumnarr := this.GetString("showcolumnarr")
  833. showcolumnnamearr := this.GetString("showcolumnnamearr")
  834. titlestring := showcolumnnamearr
  835. title = strings.Split(titlestring, ",")
  836. f := xlsx.NewFile()
  837. sheet, _ := f.AddSheet(filetitle)
  838. cellname := strings.Split(showcolumnarr, ",")
  839. row := sheet.AddRow()
  840. row.WriteSlice(&cellname, -1)
  841. for _, item := range list {
  842. var enumModel goodsaptitude.OilGoodsAptitude_2
  843. tmpModel := &item
  844. enumModel = *tmpModel
  845. immumodel := reflect.ValueOf(&enumModel)
  846. elem := immumodel.Elem()
  847. row := sheet.AddRow()
  848. for _, name := range title {
  849. cell := row.AddCell()
  850. if strings.HasPrefix(name, "F") {
  851. var val = elem.FieldByName(name).String()
  852. if val == "1" {
  853. cell.Value = "是"
  854. } else {
  855. cell.Value = ""
  856. }
  857. } else {
  858. cell.Value = elem.FieldByName(name).String()
  859. }
  860. }
  861. }
  862. for c, cl := 0, len(sheet.Cols); c < cl; c++ {
  863. sheet.Cols[c].Width = 20
  864. }
  865. dir := "static/file/excel/report/" + this.GetAccode()
  866. SaveDirectory(dir)
  867. path := dir + "/" + utils.TimeFormat(time.Now(), "200612") + filetitle + ".xlsx"
  868. f.Save(path)
  869. var sw *Seaweed
  870. var filer []string
  871. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  872. filer = []string{_filer}
  873. }
  874. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  875. _, _, fID, _ := sw.UploadFile(path, "", "")
  876. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  877. os.Remove(path)
  878. fmt.Println("==retDocWatermarkUrl==", retDocUrl)
  879. this.Data["json"] = retDocUrl
  880. this.ServeJSON()
  881. elapsed := time.Since(t)
  882. fmt.Println(elapsed)
  883. }