2
3

goodsaptitudeclass.go 9.6 KB

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