supplierpausereason.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. package oilsupplier
  2. import (
  3. "dashoo.cn/business/userRole"
  4. "dashoo.cn/backend/api/business/baseUser"
  5. "dashoo.cn/backend/api/business/oilsupplier/supplierpausereason"
  6. . "dashoo.cn/backend/api/controllers"
  7. "dashoo.cn/utils"
  8. "encoding/json"
  9. "strings"
  10. "time"
  11. )
  12. type OilSupplierPauseReasonController struct {
  13. BaseController
  14. }
  15. // @Title 获取列表
  16. // @Description get user by token
  17. // @Success 200 {object} []supplierpausereason.OilSupplierPauseReason
  18. // @router /list [get]
  19. func (this *OilSupplierPauseReasonController) 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. SupplierId := this.GetString("SupplierId")
  35. SupplierCertId := this.GetString("SupplierCertId")
  36. CertSubId := this.GetString("CertSubId")
  37. CertSubStatus := this.GetString("CertSubStatus")
  38. BackReason := this.GetString("BackReason")
  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 SupplierId != "" {
  49. where = where + " and SupplierId like '%" + SupplierId + "%'"
  50. }
  51. if SupplierCertId != "" {
  52. where = where + " and SupplierCertId like '%" + SupplierCertId + "%'"
  53. }
  54. if CertSubId != "" {
  55. where = where + " and CertSubId like '%" + CertSubId + "%'"
  56. }
  57. if CertSubStatus != "" {
  58. where = where + " and CertSubStatus like '%" + CertSubStatus + "%'"
  59. }
  60. if BackReason != "" {
  61. where = where + " and BackReason like '%" + BackReason + "%'"
  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 := supplierpausereason.GetOilSupplierPauseReasonService(utils.DBE)
  90. var list []supplierpausereason.OilSupplierPauseReason
  91. total := svc.GetPagingEntitiesWithOrderBytbl("", 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} []supplierpausereason.OilSupplierPauseReason
  103. // @router /listnopage [get]
  104. func (this *OilSupplierPauseReasonController) GetEntityListNoPage() {
  105. where := " 1=1 "
  106. Id := this.GetString("Id")
  107. SupplierId := this.GetString("SupplierId")
  108. SupplierCertId := this.GetString("SupplierCertId")
  109. CertSubId := this.GetString("CertSubId")
  110. CertSubStatus := this.GetString("CertSubStatus")
  111. BackReason := this.GetString("BackReason")
  112. CreateOn := this.GetString("CreateOn")
  113. CreateUserId := this.GetString("CreateUserId")
  114. CreateBy := this.GetString("CreateBy")
  115. ModifiedOn := this.GetString("ModifiedOn")
  116. ModifiedUserId := this.GetString("ModifiedUserId")
  117. ModifiedBy := this.GetString("ModifiedBy")
  118. if Id != "" {
  119. where = where + " and Id like '%" + Id + "%'"
  120. }
  121. if SupplierId != "" {
  122. where = where + " and SupplierId like '%" + SupplierId + "%'"
  123. }
  124. if SupplierCertId != "" {
  125. where = where + " and SupplierCertId like '%" + SupplierCertId + "%'"
  126. }
  127. if CertSubId != "" {
  128. where = where + " and CertSubId like '%" + CertSubId + "%'"
  129. }
  130. if CertSubStatus != "" {
  131. where = where + " and CertSubStatus like '%" + CertSubStatus + "%'"
  132. }
  133. if BackReason != "" {
  134. where = where + " and BackReason like '%" + BackReason + "%'"
  135. }
  136. if CreateOn != "" {
  137. where = where + " and CreateOn like '%" + CreateOn + "%'"
  138. }
  139. if CreateUserId != "" {
  140. where = where + " and CreateUserId like '%" + CreateUserId + "%'"
  141. }
  142. if CreateBy != "" {
  143. where = where + " and CreateBy like '%" + CreateBy + "%'"
  144. }
  145. if ModifiedOn != "" {
  146. where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
  147. }
  148. if ModifiedUserId != "" {
  149. where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
  150. }
  151. if ModifiedBy != "" {
  152. where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
  153. }
  154. svc := supplierpausereason.GetOilSupplierPauseReasonService(utils.DBE)
  155. var list []supplierpausereason.OilSupplierPauseReason
  156. svc.GetEntitysByWhere(OilSupplierPauseReasonName, where, &list)
  157. var datainfo DataInfo
  158. datainfo.Items = list
  159. this.Data["json"] = &datainfo
  160. this.ServeJSON()
  161. }
  162. // @Title 获取字典列表
  163. // @Description get user by token
  164. // @Success 200 {object} map[string]interface{}
  165. // @router /dictlist [get]
  166. func (this *OilSupplierPauseReasonController) GetDictList() {
  167. dictList := make(map[string]interface{})
  168. //dictSvc := items.GetItemsService(utils.DBE)
  169. userSvc := baseUser.GetBaseUserService(utils.DBE)
  170. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  171. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", "")
  172. var userEntity userRole.Base_User
  173. userSvc.GetEntityById(this.User.Id, &userEntity)
  174. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId("", userEntity.Departmentid)
  175. //var dictCustomer []svccustomer.Customer
  176. //customerSvc.GetEntitysByWhere("" + CustomerName, "", &dictCustomer)
  177. //dictList["EntrustCorp"] = &dictCustomer
  178. var datainfo DataInfo
  179. datainfo.Items = dictList
  180. this.Data["json"] = &datainfo
  181. this.ServeJSON()
  182. }
  183. // @Title 获取实体
  184. // @Description 获取实体
  185. // @Success 200 {object} supplierpausereason.OilSupplierPauseReason
  186. // @router /get/:id [get]
  187. func (this *OilSupplierPauseReasonController) GetEntity() {
  188. Id := this.Ctx.Input.Param(":id")
  189. var model supplierpausereason.OilSupplierPauseReason
  190. svc := supplierpausereason.GetOilSupplierPauseReasonService(utils.DBE)
  191. svc.GetEntityByIdBytbl(OilSupplierPauseReasonName, Id, &model)
  192. this.Data["json"] = &model
  193. this.ServeJSON()
  194. }
  195. // @Title 添加
  196. // @Description 新增
  197. // @Param body body supplierpausereason.OilSupplierPauseReason
  198. // @Success 200 {object} controllers.Request
  199. // @router /add [post]
  200. func (this *OilSupplierPauseReasonController) AddEntity() {
  201. var model supplierpausereason.OilSupplierPauseReason
  202. var jsonBlob = this.Ctx.Input.RequestBody
  203. svc := supplierpausereason.GetOilSupplierPauseReasonService(utils.DBE)
  204. json.Unmarshal(jsonBlob, &model)
  205. model.CreateOn = time.Now()
  206. model.CreateBy = this.User.Realname
  207. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  208. _, err := svc.InsertEntityBytbl(OilSupplierPauseReasonName, &model)
  209. var errinfo ErrorDataInfo
  210. if err == nil {
  211. //新增
  212. errinfo.Message = "添加成功!"
  213. errinfo.Code = 0
  214. errinfo.Item = model.Id
  215. this.Data["json"] = &errinfo
  216. this.ServeJSON()
  217. } else {
  218. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  219. errinfo.Code = -1
  220. this.Data["json"] = &errinfo
  221. this.ServeJSON()
  222. }
  223. }
  224. // @Title 修改实体
  225. // @Description 修改实体
  226. // @Param body body supplierpausereason.OilSupplierPauseReason
  227. // @Success 200 {object} controllers.Request
  228. // @router /update/:id [post]
  229. func (this *OilSupplierPauseReasonController) UpdateEntity() {
  230. id := this.Ctx.Input.Param(":id")
  231. var errinfo ErrorInfo
  232. if id == "" {
  233. errinfo.Message = "操作失败!请求信息不完整"
  234. errinfo.Code = -2
  235. this.Data["json"] = &errinfo
  236. this.ServeJSON()
  237. return
  238. }
  239. var model supplierpausereason.OilSupplierPauseReason
  240. svc := supplierpausereason.GetOilSupplierPauseReasonService(utils.DBE)
  241. var jsonBlob = this.Ctx.Input.RequestBody
  242. json.Unmarshal(jsonBlob, &model)
  243. model.ModifiedOn = time.Now()
  244. model.ModifiedBy = this.User.Realname
  245. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  246. cols := []string{
  247. "Id",
  248. "SupplierId",
  249. "SupplierCertId",
  250. "CertSubId",
  251. "CertSubStatus",
  252. "BackReason",
  253. "CreateOn",
  254. "CreateUserId",
  255. "CreateBy",
  256. "ModifiedOn",
  257. "ModifiedUserId",
  258. "ModifiedBy",
  259. }
  260. err := svc.UpdateEntityBytbl(OilSupplierPauseReasonName, id, &model, cols)
  261. if err == nil {
  262. errinfo.Message = "修改成功!"
  263. errinfo.Code = 0
  264. this.Data["json"] = &errinfo
  265. this.ServeJSON()
  266. } else {
  267. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  268. errinfo.Code = -1
  269. this.Data["json"] = &errinfo
  270. this.ServeJSON()
  271. }
  272. }
  273. // @Title 删除单条信息
  274. // @Description
  275. // @Success 200 {object} ErrorInfo
  276. // @Failure 403 :id 为空
  277. // @router /delete/:Id [delete]
  278. func (this *OilSupplierPauseReasonController) DeleteEntity() {
  279. Id := this.Ctx.Input.Param(":Id")
  280. var errinfo ErrorInfo
  281. if Id == "" {
  282. errinfo.Message = "操作失败!请求信息不完整"
  283. errinfo.Code = -2
  284. this.Data["json"] = &errinfo
  285. this.ServeJSON()
  286. return
  287. }
  288. var model supplierpausereason.OilSupplierPauseReason
  289. var entityempty supplierpausereason.OilSupplierPauseReason
  290. svc := supplierpausereason.GetOilSupplierPauseReasonService(utils.DBE)
  291. opdesc := "删除-" + Id
  292. err := svc.DeleteOperationAndWriteLogBytbl(OilSupplierPauseReasonName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "钻井日报")
  293. if err == nil {
  294. errinfo.Message = "删除成功"
  295. errinfo.Code = 0
  296. this.Data["json"] = &errinfo
  297. this.ServeJSON()
  298. } else {
  299. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  300. errinfo.Code = -1
  301. this.Data["json"] = &errinfo
  302. this.ServeJSON()
  303. }
  304. }