goodsaptitude.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. package oilsupplier
  2. import (
  3. "dashoo.cn/backend/api/business/oilsupplier/goodsaptitudeclass"
  4. "encoding/json"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "dashoo.cn/backend/api/business/items"
  9. "dashoo.cn/backend/api/business/baseUser"
  10. "dashoo.cn/backend/api/business/oilsupplier/goodsaptitude"
  11. . "dashoo.cn/backend/api/controllers"
  12. "dashoo.cn/business2/userRole"
  13. "dashoo.cn/utils"
  14. )
  15. type OilGoodsAptitudeController struct {
  16. BaseController
  17. }
  18. // @Title 获取列表
  19. // @Description get user by token
  20. // @Success 200 {object} []goodsaptitude.OilGoodsAptitude
  21. // @router /list [get]
  22. func (this *OilGoodsAptitudeController) GetEntityList() {
  23. //获取分页信息
  24. page := this.GetPageInfoForm()
  25. where := " 1=1 "
  26. orderby := "Code"
  27. asc := true
  28. Order := this.GetString("Order")
  29. Prop := this.GetString("Prop")
  30. if Order != "" && Prop != "" {
  31. orderby = Prop
  32. if Order == "asc" {
  33. asc = true
  34. } else {
  35. asc = false
  36. }
  37. }
  38. CreateOn := this.GetString("CreateOn")
  39. Code := this.GetString("Code")
  40. Name := this.GetString("Name")
  41. BigClassName := this.GetString("BigClassName")
  42. BigClassCode := this.GetString("BigClassCode")
  43. MiddleClassName := this.GetString("MiddleClassName")
  44. SmallClassName := this.GetString("SmallClassName")
  45. GoodsName := this.GetString("GoodsName")
  46. GoodsLevel := this.GetString("GoodsLevel")
  47. GoodsDesc := this.GetString("GoodsDesc")
  48. Standard := this.GetString("Standard")
  49. CompanyType := this.GetString("CompanyType")
  50. if Code != "" {
  51. where = where + " and Code like '%" + Code + "%'"
  52. }
  53. if Name != "" {
  54. where = where + " and Name like '%" + Name + "%'"
  55. }
  56. if BigClassName != "" {
  57. where = where + " and Name1 like '%" + BigClassName + "%'"
  58. }
  59. if BigClassCode != "" {
  60. where = where + " and Code1 like '%" + BigClassCode + "%'"
  61. }
  62. if MiddleClassName != "" {
  63. where = where + " and Name2 like '%" + MiddleClassName + "%'"
  64. }
  65. if SmallClassName != "" {
  66. where = where + " and Name3 '%" + SmallClassName + "%'"
  67. }
  68. if GoodsName != "" {
  69. where = where + " and Name4 like '%" + GoodsName + "%'"
  70. }
  71. if GoodsLevel != "" {
  72. where = where + " and GoodsLevel like '%" + GoodsLevel + "%'"
  73. }
  74. if GoodsDesc != "" {
  75. where = where + " and GoodsDesc like '%" + GoodsDesc + "%'"
  76. }
  77. if Standard != "" {
  78. where = where + " and Standard '%" + Standard + "%'"
  79. }
  80. if CompanyType != "" {
  81. where = where + " and CompanyType '%" + CompanyType + "%'"
  82. }
  83. if CreateOn != "" {
  84. dates := strings.Split(CreateOn, ",")
  85. if len(dates) == 2 {
  86. minDate := dates[0]
  87. maxDate := dates[1]
  88. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  89. }
  90. }
  91. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  92. var list []goodsaptitude.OilGoodsAptitudeView
  93. total := svc.GetMyPagingEntitiesWithOrderBytbl(OilGoodsAptDetailViewName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  94. var datainfo DataInfo
  95. datainfo.Items = list
  96. datainfo.CurrentItemCount = total
  97. datainfo.PageIndex = page.CurrentPage
  98. datainfo.ItemsPerPage = page.Size
  99. this.Data["json"] = &datainfo
  100. this.ServeJSON()
  101. }
  102. // @Title 获取字典列表
  103. // @Description get user by token
  104. // @Success 200 {object} map[string]interface{}
  105. // @router /dictlist [get]
  106. func (this *OilGoodsAptitudeController) GetDictList() {
  107. dictList := make(map[string]interface{})
  108. dictSvc := items.GetItemsService(utils.DBE)
  109. userSvc := baseUser.GetBaseUserService(utils.DBE)
  110. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  111. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", "")
  112. var userEntity userRole.Base_User
  113. userSvc.GetEntityById(this.User.Id, &userEntity)
  114. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId("", userEntity.Departmentid)
  115. dictList["AuditStep"] = dictSvc.GetKeyValueItems("AuditStep", this.User.AccCode)
  116. //var dictCustomer []svccustomer.Customer
  117. //customerSvc.GetEntitysByWhere("" + CustomerName, "", &dictCustomer)
  118. //dictList["EntrustCorp"] = &dictCustomer
  119. var datainfo DataInfo
  120. datainfo.Items = dictList
  121. this.Data["json"] = &datainfo
  122. this.ServeJSON()
  123. }
  124. // @Title 获取实体
  125. // @Description 获取实体
  126. // @Success 200 {object} goodsaptitude.OilGoodsAptitude
  127. // @router /get/:id [get]
  128. func (this *OilGoodsAptitudeController) GetEntity() {
  129. Id := this.Ctx.Input.Param(":id")
  130. var model goodsaptitude.OilGoodsAptitudeView
  131. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  132. //svc.GetEntityByIdBytbl(""+OilGoodsAptitudeName, Id, &model)
  133. where := " Id =" + Id
  134. svc.GetEntityByWhere(OilGoodsAptDetailViewName, where, &model)
  135. this.Data["json"] = &model
  136. this.ServeJSON()
  137. }
  138. // @Title 添加
  139. // @Description 新增
  140. // @Success 200 {object} controllers.Request
  141. // @router /add/:id [post]
  142. func (this *OilGoodsAptitudeController) AddEntity() {
  143. classId := this.Ctx.Input.Param(":id")
  144. var model goodsaptitude.OilGoodsAptitude
  145. var jsonBlob = this.Ctx.Input.RequestBody
  146. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  147. json.Unmarshal(jsonBlob, &model)
  148. model.CreateOn = time.Now()
  149. model.CreateBy = this.User.Realname
  150. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  151. model.ClassId, _ = strconv.Atoi(classId)
  152. //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  153. _, err := svc.InsertEntityBytbl(""+OilGoodsAptitudeName, &model)
  154. var errinfo ErrorDataInfo
  155. if err == nil {
  156. //新增
  157. errinfo.Message = "添加成功!"
  158. errinfo.Code = 0
  159. errinfo.Item = model.Id
  160. this.Data["json"] = &errinfo
  161. this.ServeJSON()
  162. } else {
  163. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  164. errinfo.Code = -1
  165. this.Data["json"] = &errinfo
  166. this.ServeJSON()
  167. }
  168. }
  169. // @Title 修改实体
  170. // @Description 修改实体
  171. // @Success 200 {object} controllers.Request
  172. // @router /update/:id [post]
  173. func (this *OilGoodsAptitudeController) UpdateEntity() {
  174. id := this.Ctx.Input.Param(":id")
  175. var errinfo ErrorInfo
  176. if id == "" {
  177. errinfo.Message = "操作失败!请求信息不完整"
  178. errinfo.Code = -2
  179. this.Data["json"] = &errinfo
  180. this.ServeJSON()
  181. return
  182. }
  183. var model goodsaptitude.OilGoodsAptitude
  184. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  185. var jsonBlob = this.Ctx.Input.RequestBody
  186. json.Unmarshal(jsonBlob, &model)
  187. model.ModifiedOn = time.Now()
  188. model.ModifiedBy = this.User.Realname
  189. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  190. cols := []string{
  191. "Id",
  192. "Code",
  193. "Name",
  194. "BigClassName",
  195. "MiddleClassName",
  196. "SmallClassName",
  197. "GoodsName",
  198. "GoodsLevel",
  199. "GoodsDesc",
  200. "Standard",
  201. "CompanyType",
  202. "F01",
  203. "F02",
  204. "F03",
  205. "F04",
  206. "F05",
  207. "F06",
  208. "F07",
  209. "F08",
  210. "F09",
  211. "F10",
  212. "F11",
  213. "F12",
  214. "F13",
  215. "F14",
  216. "F15",
  217. "F16",
  218. "F17",
  219. "F18",
  220. "F19",
  221. "F20",
  222. "F21",
  223. "F22",
  224. "F23",
  225. "F24",
  226. "F25",
  227. "F26",
  228. "F27",
  229. "F28",
  230. "F29",
  231. "F30",
  232. "F31",
  233. "F32",
  234. "F33",
  235. "F34",
  236. "F35",
  237. "F36",
  238. "F37",
  239. "F38",
  240. "F39",
  241. "F40",
  242. "F41",
  243. "F42",
  244. "F43",
  245. "F44",
  246. "F45",
  247. "F46",
  248. "Remark",
  249. "DeletionStateCode",
  250. "CreateOn",
  251. "CreateUserId",
  252. "CreateBy",
  253. "ModifiedOn",
  254. "ModifiedUserId",
  255. "ModifiedBy",
  256. }
  257. err := svc.UpdateEntityBytbl(""+OilGoodsAptitudeName, id, &model, cols)
  258. if err == nil {
  259. errinfo.Message = "修改成功!"
  260. errinfo.Code = 0
  261. this.Data["json"] = &errinfo
  262. this.ServeJSON()
  263. } else {
  264. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  265. errinfo.Code = -1
  266. this.Data["json"] = &errinfo
  267. this.ServeJSON()
  268. }
  269. }
  270. // @Title 修改实体
  271. // @Description 修改实体
  272. // @Success 200 {object} controllers.Request
  273. // @router /updatecode/:id [post]
  274. func (this *OilGoodsAptitudeController) UpdateCodeEntity() {
  275. var errinfo ErrorInfo
  276. var err error
  277. id := this.Ctx.Input.Param(":id")
  278. if id == "" {
  279. errinfo.Message = "操作失败!请求信息不完整"
  280. errinfo.Code = -2
  281. this.Data["json"] = &errinfo
  282. this.ServeJSON()
  283. return
  284. }
  285. var classall goodsaptitude.OilGoodsAptitudeClassView
  286. var model goodsaptitudeclass.OilGoodsAptitudeClass
  287. var classmodel []goodsaptitudeclass.OilGoodsAptitudeClass
  288. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  289. var jsonBlob = this.Ctx.Input.RequestBody
  290. json.Unmarshal(jsonBlob, &classall)
  291. model.ModifiedOn = time.Now()
  292. model.ModifiedBy = this.User.Realname
  293. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  294. colsName := []string{"Name"}
  295. colsCode := []string{"Code"}
  296. //svc.GetEntityById(id, &model)
  297. if classall.Name1 != ""{
  298. where := " Name = '" + classall.Name1 +"' and Id <> "+utils.ToStr(classall.Id1)
  299. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  300. if len(classmodel) > 0 {
  301. errinfo.Message = "大类名称已存在,请重新添加!"
  302. errinfo.Code = -1
  303. this.Data["json"] = &errinfo
  304. this.ServeJSON()
  305. return
  306. }else {
  307. model.Name = classall.Name1
  308. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id1, &model, colsName)
  309. }
  310. }
  311. if classall.Name2 != ""{
  312. where := " Name = '" + classall.Name2 +"' and Id <> "+utils.ToStr(classall.Id2)
  313. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  314. if len(classmodel) > 0 {
  315. errinfo.Message = "中类名称已存在,请重新添加!"
  316. errinfo.Code = -1
  317. this.Data["json"] = &errinfo
  318. this.ServeJSON()
  319. return
  320. }else {
  321. model.Name = classall.Name2
  322. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id2, &model, colsName)
  323. }
  324. }
  325. if classall.Name3 != ""{
  326. where := " Name = '" + classall.Name3 +"' and Id <> "+utils.ToStr(classall.Id3)
  327. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  328. if len(classmodel) > 0 {
  329. errinfo.Message = "小类名称已存在,请重新添加!"
  330. errinfo.Code = -1
  331. this.Data["json"] = &errinfo
  332. this.ServeJSON()
  333. return
  334. }else {
  335. model.Name = classall.Name3
  336. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id3, &model, colsName)
  337. }
  338. }
  339. if classall.Name4 != ""{
  340. where := " Name = '" + classall.Name4 + "' and Id <> "+utils.ToStr(classall.Id4)
  341. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  342. if len(classmodel) > 0 {
  343. errinfo.Message = "品名已存在,请重新添加!"
  344. errinfo.Code = -1
  345. this.Data["json"] = &errinfo
  346. this.ServeJSON()
  347. return
  348. }else {
  349. model.Name = classall.Name4
  350. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id4, &model, colsName)
  351. }
  352. }
  353. if classall.Code1 != ""{
  354. where := " Code = " + classall.Code1 +" and Id <> "+utils.ToStr(classall.Id1)
  355. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  356. if len(classmodel) > 0 {
  357. errinfo.Message = "大类编码已存在,请重新添加!"
  358. errinfo.Code = -1
  359. this.Data["json"] = &errinfo
  360. this.ServeJSON()
  361. return
  362. }else {
  363. model.Code = classall.Code1
  364. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id1, &model, colsCode)
  365. }
  366. }
  367. if classall.Code2 != ""{
  368. where := " Code = " + classall.Code2 +" and Id <> "+utils.ToStr(classall.Id2)
  369. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  370. if len(classmodel) > 0 {
  371. errinfo.Message = "中类编码已存在,请重新添加!"
  372. errinfo.Code = -1
  373. this.Data["json"] = &errinfo
  374. this.ServeJSON()
  375. return
  376. }else {
  377. model.Code = classall.Code2
  378. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id2, &model, colsCode)
  379. }
  380. }
  381. if classall.Code3 != ""{
  382. where := " Code = " + classall.Code3 +" and Id <> "+utils.ToStr(classall.Id3)
  383. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  384. if len(classmodel) > 0 {
  385. errinfo.Message = "小类编码已存在,请重新添加!"
  386. errinfo.Code = -1
  387. this.Data["json"] = &errinfo
  388. this.ServeJSON()
  389. return
  390. }else {
  391. model.Code = classall.Code3
  392. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id3, &model, colsCode)
  393. }
  394. }
  395. if classall.Code4 != ""{
  396. where := " Code = " + classall.Code4 +" and Id <> "+utils.ToStr(classall.Id4)
  397. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  398. if len(classmodel) > 0 {
  399. errinfo.Message = "品名编码已存在,请重新添加!"
  400. errinfo.Code = -1
  401. this.Data["json"] = &errinfo
  402. this.ServeJSON()
  403. return
  404. }else {
  405. model.Code = classall.Code4
  406. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id4, &model, colsCode)
  407. }
  408. }
  409. if err == nil {
  410. errinfo.Message = "修改成功!"
  411. errinfo.Code = 0
  412. this.Data["json"] = &errinfo
  413. this.ServeJSON()
  414. } else {
  415. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  416. errinfo.Code = -1
  417. this.Data["json"] = &errinfo
  418. this.ServeJSON()
  419. }
  420. }
  421. // @Title 删除单条信息
  422. // @Description
  423. // @Success 200 {object} ErrorInfo
  424. // @Failure 403 :id 为空
  425. // @router /delete/:Id [delete]
  426. func (this *OilGoodsAptitudeController) DeleteEntity() {
  427. Id := this.Ctx.Input.Param(":Id")
  428. var errinfo ErrorInfo
  429. if Id == "" {
  430. errinfo.Message = "操作失败!请求信息不完整"
  431. errinfo.Code = -2
  432. this.Data["json"] = &errinfo
  433. this.ServeJSON()
  434. return
  435. }
  436. var model goodsaptitude.OilGoodsAptitude
  437. var entityempty goodsaptitude.OilGoodsAptitude
  438. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  439. opdesc := "删除-" + Id
  440. err := svc.DeleteOperationAndWriteLogBytbl(""+OilGoodsAptitudeName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "钻井日报")
  441. if err == nil {
  442. errinfo.Message = "删除成功"
  443. errinfo.Code = 0
  444. this.Data["json"] = &errinfo
  445. this.ServeJSON()
  446. } else {
  447. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  448. errinfo.Code = -1
  449. this.Data["json"] = &errinfo
  450. this.ServeJSON()
  451. }
  452. }
  453. // @Title get 查询
  454. // @Description get SampleType by token
  455. // @Success 200 {object} sampletype.SampleType
  456. // @router /goodsparentlist/:name [get]
  457. func (this *OilGoodsAptitudeController) GoodsParentList() {
  458. Name := this.Ctx.Input.Param(":name")
  459. if Name != "" {
  460. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  461. where1 := "1=1"
  462. where1 += " AND Name LIKE '%" + Name + "%' OR Code LIKE '" + Name + "%' "
  463. sqlStr := "SELECT Id, Code, Name, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass " +
  464. "WHERE " + where1 + " AND DeletionStateCode = 0 ORDER BY Code"
  465. list, _ := svc.DBE.QueryString(sqlStr)
  466. /*
  467. sql := "SELECT Id, Code, Name, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass " +
  468. "WHERE DeletionStateCode = 0 AND " + where1 + " OR Id = (" + sqlStr + ")" +" ORDER BY Code"
  469. list, _ := svc.DBE.QueryString(sql)*/
  470. var datainfo DataInfo
  471. datainfo.Items = list
  472. this.Data["json"] = &datainfo
  473. this.ServeJSON()
  474. }
  475. }
  476. // @Title get 获取子类
  477. // @Description get SampleType by token
  478. // @Success 200 {object} sampletype.SampleType
  479. // @router /goodschildlist/:id [get]
  480. func (this *OilGoodsAptitudeController) GoodsChildList() {
  481. ParentId := this.Ctx.Input.Param(":id")
  482. 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"
  483. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  484. list, _ := svc.DBE.QueryString(sqlStr)
  485. var datainfo DataInfo
  486. datainfo.Items = list
  487. this.Data["json"] = &datainfo
  488. this.ServeJSON()
  489. }
  490. // @Title get 获取子类
  491. // @Description get SampleType by token
  492. // @Success 200 {object} sampletype.SampleType
  493. // @router /goodschildlistbypid/:parentid [get]
  494. func (this *OilGoodsAptitudeController) GoodsChildLisByParentId() {
  495. ParentId := this.Ctx.Input.Param(":parentid")
  496. 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 DeletionStateCode = 0 order by Code"
  497. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  498. list, _ := svc.DBE.QueryString(sqlStr)
  499. var datainfo DataInfo
  500. datainfo.Items = list
  501. this.Data["json"] = &datainfo
  502. this.ServeJSON()
  503. }