2
3

goodsaptitudeclass.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. package oilsupplier
  2. import (
  3. "dashoo.cn/backend/api/business/oilsupplier/goodsaptitude"
  4. "dashoo.cn/backend/api/business/organize"
  5. "encoding/json"
  6. "strings"
  7. "time"
  8. "dashoo.cn/backend/api/business/baseUser"
  9. "dashoo.cn/backend/api/business/oilsupplier/goodsaptitudeclass"
  10. . "dashoo.cn/backend/api/controllers"
  11. "dashoo.cn/business2/userRole"
  12. "dashoo.cn/utils"
  13. )
  14. type OilGoodsAptitudeClassController struct {
  15. BaseController
  16. }
  17. // @Title 获取列表
  18. // @Description get user by token
  19. // @Success 200 {object} []goodsaptitudeclass.OilGoodsAptitudeClass
  20. // @router /list [get]
  21. func (this *OilGoodsAptitudeClassController) GetEntityList() {
  22. //获取分页信息
  23. page := this.GetPageInfoForm()
  24. where := " 1=1 "
  25. orderby := "Id"
  26. asc := false
  27. Order := this.GetString("Order")
  28. Prop := this.GetString("Prop")
  29. if Order != "" && Prop != "" {
  30. orderby = Prop
  31. if Order == "asc" {
  32. asc = true
  33. }
  34. }
  35. Id := this.GetString("Id")
  36. Code := this.GetString("Code")
  37. Name := this.GetString("Name")
  38. ParentId := this.GetString("ParentId")
  39. Remark := this.GetString("Remark")
  40. DeletionStateCode := this.GetString("DeletionStateCode")
  41. CreateOn := this.GetString("CreateOn")
  42. CreateUserId := this.GetString("CreateUserId")
  43. CreateBy := this.GetString("CreateBy")
  44. ModifiedOn := this.GetString("ModifiedOn")
  45. ModifiedUserId := this.GetString("ModifiedUserId")
  46. ModifiedBy := this.GetString("ModifiedBy")
  47. if Id != "" {
  48. where = where + " and Id like '%" + Id + "%'"
  49. }
  50. if Code != "" {
  51. where = where + " and Code like '%" + Code + "%'"
  52. }
  53. if Name != "" {
  54. where = where + " and Name like '%" + Name + "%'"
  55. }
  56. if ParentId != "" {
  57. where = where + " and ParentId like '%" + ParentId + "%'"
  58. }
  59. if Remark != "" {
  60. where = where + " and Remark like '%" + Remark + "%'"
  61. }
  62. if DeletionStateCode != "" {
  63. where = where + " and DeletionStateCode like '%" + DeletionStateCode + "%'"
  64. }
  65. if CreateOn != "" {
  66. where = where + " and CreateOn like '%" + CreateOn + "%'"
  67. }
  68. if CreateUserId != "" {
  69. where = where + " and CreateUserId like '%" + CreateUserId + "%'"
  70. }
  71. if CreateBy != "" {
  72. where = where + " and CreateBy like '%" + CreateBy + "%'"
  73. }
  74. if ModifiedOn != "" {
  75. where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
  76. }
  77. if ModifiedUserId != "" {
  78. where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
  79. }
  80. if ModifiedBy != "" {
  81. where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
  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 := goodsaptitudeclass.GetOilGoodsAptitudeClassService(utils.DBE)
  92. var list []goodsaptitudeclass.OilGoodsAptitudeClass
  93. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, 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 *OilGoodsAptitudeClassController) 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", this.User.AccCode)
  112. var userEntity userRole.Base_User
  113. userSvc.GetEntityById(this.User.Id, &userEntity)
  114. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId(this.User.AccCode, userEntity.Departmentid)
  115. //var dictCustomer []svccustomer.Customer
  116. //customerSvc.GetEntitysByWhere(this.User.AccCode + CustomerName, "", &dictCustomer)
  117. //dictList["EntrustCorp"] = &dictCustomer
  118. var datainfo DataInfo
  119. datainfo.Items = dictList
  120. this.Data["json"] = &datainfo
  121. this.ServeJSON()
  122. }
  123. // @Title 获取实体
  124. // @Description 获取实体
  125. // @Success 200 {object} goodsaptitudeclass.OilGoodsAptitudeClass
  126. // @router /get/:id [get]
  127. func (this *OilGoodsAptitudeClassController) GetEntity() {
  128. Id := this.Ctx.Input.Param(":id")
  129. var model goodsaptitudeclass.OilGoodsAptitudeClass
  130. svc := goodsaptitudeclass.GetOilGoodsAptitudeClassService(utils.DBE)
  131. svc.GetEntityByIdBytbl(OilGoodsAptitudeClassName, Id, &model)
  132. this.Data["json"] = &model
  133. this.ServeJSON()
  134. }
  135. // @Title 获取实体
  136. // @Description 获取实体
  137. // @Success 200 {object} technologyserviceclass.OilGoodsAptitudeClass
  138. // @router /getcodename/:id [get]
  139. func (this *OilGoodsAptitudeClassController) GetCodeEntity() {
  140. Id := this.Ctx.Input.Param(":id")
  141. where := " Code = "+ Id
  142. var model goodsaptitude.OilGoodsAptitudeClassView
  143. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  144. //svc.GetEntityByIdBytbl(""+OilGoodsAptitudeName, Id, &model)
  145. svc.GetEntityByWhere(OilGoodsAptClassViewName, where, &model)
  146. this.Data["json"] = &model
  147. this.ServeJSON()
  148. }
  149. // @Title 添加
  150. // @Description 新增
  151. // @Success 200 {object} controllers.Request
  152. // @router /add [post]
  153. func (this *OilGoodsAptitudeClassController) AddEntity() {
  154. var model goodsaptitudeclass.OilGoodsAptitudeClass
  155. var jsonBlob = this.Ctx.Input.RequestBody
  156. svc := goodsaptitudeclass.GetOilGoodsAptitudeClassService(utils.DBE)
  157. json.Unmarshal(jsonBlob, &model)
  158. model.CreateOn = time.Now()
  159. model.CreateBy = this.User.Realname
  160. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  161. //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  162. _, err := svc.InsertEntityBytbl(OilGoodsAptitudeClassName, &model)
  163. var errinfo ErrorDataInfo
  164. if err == nil {
  165. //新增
  166. errinfo.Message = "添加成功!"
  167. errinfo.Code = 0
  168. errinfo.Item = model.Id
  169. this.Data["json"] = &errinfo
  170. this.ServeJSON()
  171. } else {
  172. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  173. errinfo.Code = -1
  174. this.Data["json"] = &errinfo
  175. this.ServeJSON()
  176. }
  177. }
  178. // @Title 修改实体
  179. // @Description 修改实体
  180. // @Success 200 {object} controllers.Request
  181. // @router /update/:id [post]
  182. func (this *OilGoodsAptitudeClassController) UpdateEntity() {
  183. id := this.Ctx.Input.Param(":id")
  184. var errinfo ErrorInfo
  185. if id == "" {
  186. errinfo.Message = "操作失败!请求信息不完整"
  187. errinfo.Code = -2
  188. this.Data["json"] = &errinfo
  189. this.ServeJSON()
  190. return
  191. }
  192. var model goodsaptitudeclass.OilGoodsAptitudeClass
  193. svc := goodsaptitudeclass.GetOilGoodsAptitudeClassService(utils.DBE)
  194. var jsonBlob = this.Ctx.Input.RequestBody
  195. json.Unmarshal(jsonBlob, &model)
  196. model.ModifiedOn = time.Now()
  197. model.ModifiedBy = this.User.Realname
  198. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  199. cols := []string{
  200. "Id",
  201. "Code",
  202. "Name",
  203. "ParentId",
  204. "Remark",
  205. "DeletionStateCode",
  206. "CreateOn",
  207. "CreateUserId",
  208. "CreateBy",
  209. "ModifiedOn",
  210. "ModifiedUserId",
  211. "ModifiedBy",
  212. }
  213. err := svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, id, &model, cols)
  214. if err == nil {
  215. errinfo.Message = "修改成功!"
  216. errinfo.Code = 0
  217. this.Data["json"] = &errinfo
  218. this.ServeJSON()
  219. } else {
  220. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  221. errinfo.Code = -1
  222. this.Data["json"] = &errinfo
  223. this.ServeJSON()
  224. }
  225. }
  226. // @Title 删除单条信息
  227. // @Description
  228. // @Success 200 {object} ErrorInfo
  229. // @Failure 403 :id 为空
  230. // @router /delete/:Id [delete]
  231. func (this *OilGoodsAptitudeClassController) DeleteEntity() {
  232. Id := this.Ctx.Input.Param(":Id")
  233. var errinfo ErrorInfo
  234. if Id == "" {
  235. errinfo.Message = "操作失败!请求信息不完整"
  236. errinfo.Code = -2
  237. this.Data["json"] = &errinfo
  238. this.ServeJSON()
  239. return
  240. }
  241. var model goodsaptitudeclass.OilGoodsAptitudeClass
  242. var entityempty goodsaptitudeclass.OilGoodsAptitudeClass
  243. svc := goodsaptitudeclass.GetOilGoodsAptitudeClassService(utils.DBE)
  244. opdesc := "删除-" + Id
  245. err := svc.DeleteOperationAndWriteLogBytbl(OilGoodsAptitudeClassName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报")
  246. if err == nil {
  247. errinfo.Message = "删除成功"
  248. errinfo.Code = 0
  249. this.Data["json"] = &errinfo
  250. this.ServeJSON()
  251. } else {
  252. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  253. errinfo.Code = -1
  254. this.Data["json"] = &errinfo
  255. this.ServeJSON()
  256. }
  257. }
  258. // @Title get 获取物资类资质分类第一级分类
  259. // @Description get SampleType by token
  260. // @Success 200 {object} sampletype.SampleType
  261. // @router /getgoodsclasslist/:id [get]
  262. func (this *OilGoodsAptitudeClassController) GetGoodsClassList() {
  263. ParentId := this.Ctx.Input.Param(":id")
  264. where := " 1 = 1 "
  265. if ParentId != "" {
  266. where = where + " and ParentId = " + ParentId
  267. }
  268. where = where + " and DeletionStateCode = 0 "
  269. var list []goodsaptitudeclass.GoodsAptitudeClassList
  270. svc := goodsaptitudeclass.GetOilGoodsAptitudeClassService(utils.DBE)
  271. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &list)
  272. var datainfo DataInfo
  273. datainfo.Items = list
  274. this.Data["json"] = &datainfo
  275. this.ServeJSON()
  276. }
  277. // @Title get 获取子类
  278. // @Description get SampleType by token
  279. // @Success 200 {object} sampletype.SampleType
  280. // @router /getchildlist/:id [get]
  281. func (this *OilGoodsAptitudeClassController) GetChildList() {
  282. ParentId := this.Ctx.Input.Param(":id")
  283. sqlStr := "SELECT Id, `Code`, `Name`, ParentId FROM OilGoodsAptitudeClass WHERE FIND_IN_SET(ParentId, fun_getOilGoodsAptitudeClasschildlist(" + ParentId + ")) AND DeletionStateCode = 0"
  284. svc := goodsaptitudeclass.GetOilGoodsAptitudeClassService(utils.DBE)
  285. list, _ := svc.DBE.QueryString(sqlStr)
  286. var datainfo DataInfo
  287. datainfo.Items = list
  288. this.Data["json"] = &datainfo
  289. this.ServeJSON()
  290. }
  291. // @Title 获取Code
  292. // @Description 根据Id获取Code
  293. // @Success 200 {object} technologyservice.TechnologyBusiness
  294. // @router /getcode/:id [get]
  295. func (this *OilGoodsAptitudeClassController) GetCodeById() {
  296. Id := this.Ctx.Input.Param(":id")
  297. where := " 1 = 1 "
  298. if Id != "" {
  299. where = where + " and Id = " + Id
  300. }
  301. var list []goodsaptitudeclass.GoodsAptitudeClassList
  302. svc := goodsaptitudeclass.GetOilGoodsAptitudeClassService(utils.DBE)
  303. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &list)
  304. var datainfo DataInfo
  305. datainfo.Items = list
  306. this.Data["json"] = &datainfo
  307. this.ServeJSON()
  308. }
  309. // @Title 获取物质类子类
  310. // @Description 获取物质类子类
  311. // @Success 200 {object} business.device.DeviceChannels
  312. // @router /getgoodslist/:id [get]
  313. func (this *OilGoodsAptitudeClassController) OrgAllList() {
  314. Id := this.Ctx.Input.Param(":id")
  315. svc := organize.GetOrganizeService(utils.DBE)
  316. ids := svc.GetAllGoodsChildById(Id)
  317. where := " Id in ( " + ids + " ) "
  318. list := make([]goodsaptitudeclass.OilGoodsAptitudeClass, 0)
  319. svc.GetEntities(&list, where)
  320. var datainfo DataInfo
  321. datainfo.Items = list
  322. this.Data["json"] = &datainfo
  323. this.ServeJSON()
  324. }