auditsetting.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. package system
  2. import (
  3. "dashoo.cn/backend/api/business/baseUser"
  4. "dashoo.cn/backend/api/business/items"
  5. "dashoo.cn/backend/api/business/organize"
  6. "dashoo.cn/backend/api/business/role"
  7. . "dashoo.cn/backend/api/controllers"
  8. "dashoo.cn/business2/userRole"
  9. "dashoo.cn/utils"
  10. "encoding/json"
  11. "strings"
  12. "dashoo.cn/backend/api/business/auditsetting"
  13. "time"
  14. )
  15. type OilAuditSettingController struct {
  16. BaseController
  17. }
  18. // @Title 获取列表
  19. // @Description get user by token
  20. // @Success 200 {object} []auditsetting.BaseOilAuditSetting
  21. // @router /list [get]
  22. func (this *OilAuditSettingController) GetEntityList() {
  23. //获取分页信息
  24. page := this.GetPageInfoForm()
  25. where := " 1=1 "
  26. orderby := "Id"
  27. asc := false
  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. }
  35. }
  36. OrganizeId := this.GetString("OrganizeId")
  37. OrganizeName := this.GetString("OrganizeName")
  38. AuditStepCode := this.GetString("AuditStepCode")
  39. AuditStepName := this.GetString("AuditStepName")
  40. RoleId := this.GetString("RoleId")
  41. RoleName := this.GetString("RoleName")
  42. WorkFlowCord := this.GetString("WorkFlowCord")
  43. WorkFlowName := this.GetString("WorkFlowName")
  44. Remark := this.GetString("Remark")
  45. CreateOn := this.GetString("CreateOn")
  46. OrganizeId = this.User.DepartmentId //无权限看所有时,只看当前部门的数据
  47. if OrganizeId != "" {
  48. where = where + " and OrganizeId = '" + OrganizeId + "'"
  49. }
  50. if OrganizeName != "" {
  51. where = where + " and OrganizeName like '%" + OrganizeName + "%'"
  52. }
  53. if AuditStepCode != "" {
  54. where = where + " and AuditStepCode like '%" + AuditStepCode + "%'"
  55. }
  56. if AuditStepName != "" {
  57. where = where + " and AuditStepName like '%" + AuditStepName + "%'"
  58. }
  59. if RoleId != "" {
  60. where = where + " and RoleId like '%" + RoleId + "%'"
  61. }
  62. if RoleName != "" {
  63. where = where + " and RoleName like '%" + RoleName + "%'"
  64. }
  65. if WorkFlowCord != "" {
  66. where = where + " and WorkFlowCord like '%" + WorkFlowCord + "%'"
  67. }
  68. if WorkFlowName != "" {
  69. where = where + " and WorkFlowName like '%" + WorkFlowName + "%'"
  70. }
  71. if Remark != "" {
  72. where = where + " and Remark like '%" + Remark + "%'"
  73. }
  74. if CreateOn != "" {
  75. dates := strings.Split(CreateOn, ",")
  76. if len(dates) == 2 {
  77. minDate := dates[0]
  78. maxDate := dates[1]
  79. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  80. }
  81. }
  82. svc := auditsetting.GetOilAuditSettingService(utils.DBE)
  83. var list []auditsetting.BaseOilAuditSetting
  84. total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
  85. var datainfo DataInfo
  86. datainfo.Items = list
  87. datainfo.CurrentItemCount = total
  88. datainfo.PageIndex = page.CurrentPage
  89. datainfo.ItemsPerPage = page.Size
  90. this.Data["json"] = &datainfo
  91. this.ServeJSON()
  92. }
  93. // @Title 获取字典列表
  94. // @Description get user by token
  95. // @Success 200 {object} map[string]interface{}
  96. // @router /dictlist [get]
  97. func (this *OilAuditSettingController) GetDictList() {
  98. dictList := make(map[string]interface{})
  99. dictSvc := items.GetItemsService(utils.DBE)
  100. userSvc := baseUser.GetBaseUserService(utils.DBE)
  101. dictList["AuditStep"] = dictSvc.GetKeyValueItems("AuditStep", this.User.AccCode)
  102. dictList["WorkFlow"] = dictSvc.GetKeyValueItems("WorkFlow", this.User.AccCode)
  103. var userEntity userRole.Base_User
  104. userSvc.GetEntityById(this.User.Id, &userEntity)
  105. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId(this.User.AccCode, userEntity.Departmentid)
  106. svcRole := role.GetRoleService(utils.DBE)
  107. var roles []userRole.Base_Role
  108. where := "IsVisible=1"
  109. svcRole.GetMyRoleList("CreateOn", utils.ToStr(this.User.Id), &roles, where)
  110. dictList["RoleList"] = roles
  111. svcOrgan := organize.GetOrganizeService(utils.DBE)
  112. dictList["OrganizeId"] = this.User.DepartmentId
  113. dictList["OrganizeName"] = svcOrgan.GetNameById(this.User.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} auditsetting.BaseOilAuditSetting
  125. // @router /get/:id [get]
  126. func (this *OilAuditSettingController) GetEntity() {
  127. Id := this.Ctx.Input.Param(":id")
  128. var model auditsetting.BaseOilAuditSetting
  129. svc := auditsetting.GetOilAuditSettingService(utils.DBE)
  130. svc.GetEntityByIdBytbl(OilAuditSettingName, Id, &model)
  131. this.Data["json"] = &model
  132. this.ServeJSON()
  133. }
  134. // @Title 添加
  135. // @Description 新增
  136. // @Param body body auditsetting.OilAuditSetting
  137. // @Success 200 {object} controllers.Request
  138. // @router /add [post]
  139. func (this *OilAuditSettingController) AddEntity() {
  140. var model auditsetting.BaseOilAuditSetting
  141. var jsonBlob = this.Ctx.Input.RequestBody
  142. svc := auditsetting.GetOilAuditSettingService(utils.DBE)
  143. json.Unmarshal(jsonBlob, &model)
  144. model.CreateOn = time.Now()
  145. model.CreateBy = this.User.Realname
  146. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  147. model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  148. _, err := svc.InsertEntityBytbl(OilAuditSettingName, &model)
  149. var errinfo ErrorDataInfo
  150. if err == nil {
  151. //新增
  152. errinfo.Message = "添加成功!"
  153. errinfo.Code = 0
  154. errinfo.Item = model.Id
  155. this.Data["json"] = &errinfo
  156. this.ServeJSON()
  157. } else {
  158. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  159. errinfo.Code = -1
  160. this.Data["json"] = &errinfo
  161. this.ServeJSON()
  162. }
  163. }
  164. // @Title 修改实体
  165. // @Description 修改实体
  166. // @Param body body auditsetting.OilAuditSetting
  167. // @Success 200 {object} controllers.Request
  168. // @router /update/:id [post]
  169. func (this *OilAuditSettingController) UpdateEntity() {
  170. id := this.Ctx.Input.Param(":id")
  171. var errinfo ErrorInfo
  172. if id == "" {
  173. errinfo.Message = "操作失败!请求信息不完整"
  174. errinfo.Code = -2
  175. this.Data["json"] = &errinfo
  176. this.ServeJSON()
  177. return
  178. }
  179. var model auditsetting.BaseOilAuditSetting
  180. svc := auditsetting.GetOilAuditSettingService(utils.DBE)
  181. var jsonBlob = this.Ctx.Input.RequestBody
  182. json.Unmarshal(jsonBlob, &model)
  183. model.ModifiedOn = time.Now()
  184. model.ModifiedBy = this.User.Realname
  185. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  186. cols := []string{
  187. "Id",
  188. "OrganizeId",
  189. "OrganizeName",
  190. "AuditStepCode",
  191. "AuditStepName",
  192. "RoleId",
  193. "RoleName",
  194. "WorkFlowCord",
  195. "WorkFlowName",
  196. "Remark",
  197. "IsDelete",
  198. "CreateOn",
  199. "CreateUserId",
  200. "CreateBy",
  201. "ModifiedOn",
  202. "ModifiedUserId",
  203. "ModifiedBy",
  204. }
  205. err := svc.UpdateEntityBytbl(OilAuditSettingName, id, &model, cols)
  206. if err == nil {
  207. errinfo.Message = "修改成功!"
  208. errinfo.Code = 0
  209. this.Data["json"] = &errinfo
  210. this.ServeJSON()
  211. } else {
  212. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  213. errinfo.Code = -1
  214. this.Data["json"] = &errinfo
  215. this.ServeJSON()
  216. }
  217. }
  218. // @Title 删除单条信息
  219. // @Description
  220. // @Success 200 {object} ErrorInfo
  221. // @Failure 403 :id 为空
  222. // @router /delete/:Id [delete]
  223. func (this *OilAuditSettingController) DeleteEntity() {
  224. Id := this.Ctx.Input.Param(":Id")
  225. var errinfo ErrorInfo
  226. if Id == "" {
  227. errinfo.Message = "操作失败!请求信息不完整"
  228. errinfo.Code = -2
  229. this.Data["json"] = &errinfo
  230. this.ServeJSON()
  231. return
  232. }
  233. var model auditsetting.BaseOilAuditSetting
  234. var entityempty auditsetting.BaseOilAuditSetting
  235. svc := auditsetting.GetOilAuditSettingService(utils.DBE)
  236. opdesc := "删除-" + Id
  237. err := svc.DeleteOperationAndWriteLogBytbl(OilAuditSettingName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报")
  238. if err == nil {
  239. errinfo.Message = "删除成功"
  240. errinfo.Code = 0
  241. this.Data["json"] = &errinfo
  242. this.ServeJSON()
  243. } else {
  244. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  245. errinfo.Code = -1
  246. this.Data["json"] = &errinfo
  247. this.ServeJSON()
  248. }
  249. }