goodsaptitude.go 23 KB

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