technologyserviceclass.go 8.4 KB

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