2
3

oilcatalogsub.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. package oilsupplier
  2. import (
  3. "dashoo.cn/backend/api/business/audithistory"
  4. "dashoo.cn/backend/api/business/auditsetting"
  5. "dashoo.cn/backend/api/business/oilsupplier/oilcatalog"
  6. "dashoo.cn/backend/api/business/oilsupplier/oilcatalogsub"
  7. "dashoo.cn/backend/api/business/workflow"
  8. "dashoo.cn/business3/parameter"
  9. "dashoo.cn/utils"
  10. "encoding/json"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "dashoo.cn/backend/api/business/baseUser"
  15. . "dashoo.cn/backend/api/controllers"
  16. "dashoo.cn/business3/userRole"
  17. )
  18. type OilCatalogSubController struct {
  19. BaseController
  20. }
  21. // @Title 获取列表
  22. // @Description get user by token
  23. // @Success 200 {object} []limsoilcatalogsub.OilCatalogSub
  24. // @router /list [get]
  25. func (this *OilCatalogSubController) GetEntityList() {
  26. //获取分页信息
  27. page := this.GetPageInfoForm()
  28. where := " 1=1 "
  29. orderby := "Id"
  30. asc := false
  31. Order := this.GetString("Order")
  32. Prop := this.GetString("Prop")
  33. if Order != "" && Prop != "" {
  34. orderby = Prop
  35. if Order == "asc" {
  36. asc = true
  37. }
  38. }
  39. Id := this.GetString("Id")
  40. Type := this.GetString("Type")
  41. Status := this.GetString("Status")
  42. SubmitterId := this.GetString("SubmitterId")
  43. Submitter := this.GetString("Submitter")
  44. DeptId := this.GetString("DeptId")
  45. Dept := this.GetString("Dept")
  46. FirstAudit := this.GetString("FirstAudit")
  47. SecondAudit := this.GetString("SecondAudit")
  48. BusinessKey := this.GetString("BusinessKey")
  49. ProcessKey := this.GetString("ProcessKey")
  50. CreateUserId := this.GetString("CreateUserId")
  51. CreateOn := this.GetString("CreateOn")
  52. CreateBy := this.GetString("CreateBy")
  53. ModifiedOn := this.GetString("ModifiedOn")
  54. ModifiedUserId := this.GetString("ModifiedUserId")
  55. ModifiedBy := this.GetString("ModifiedBy")
  56. SubmitOn := this.GetString("SubmitOn")
  57. if Id != "" {
  58. where = where + " and Id = " + Id
  59. }
  60. if Type != "" {
  61. where = where + " and Type = '" + Type + "'"
  62. }
  63. if Status != "" {
  64. where = where + " and Status = '" + Status + "'"
  65. }
  66. if SubmitterId != "" {
  67. where = where + " and SubmitterId = " + SubmitterId
  68. }
  69. if Submitter != "" {
  70. where = where + " and Submitter like '%" + Submitter + "%'"
  71. }
  72. if DeptId != "" {
  73. where = where + " and DeptId = " + DeptId
  74. }
  75. if Dept != "" {
  76. where = where + " and Dept like '%" + Dept + "%'"
  77. }
  78. if FirstAudit != "" {
  79. where = where + " and FirstAudit = " + FirstAudit
  80. }
  81. if SecondAudit != "" {
  82. where = where + " and SecondAudit = " + SecondAudit
  83. }
  84. if BusinessKey != "" {
  85. where = where + " and BusinessKey = '" + BusinessKey + "'"
  86. }
  87. if ProcessKey != "" {
  88. where = where + " and ProcessKey = '" + ProcessKey + "'"
  89. }
  90. if CreateUserId != "" {
  91. where = where + " and CreateUserId =" + this.User.Id
  92. }
  93. if CreateBy != "" {
  94. where = where + " and CreateBy like '%" + CreateBy + "%'"
  95. }
  96. if ModifiedOn != "" {
  97. where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
  98. }
  99. if ModifiedUserId != "" {
  100. where = where + " and ModifiedUserId =" + ModifiedUserId
  101. }
  102. if ModifiedBy != "" {
  103. where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
  104. }
  105. if CreateOn != "" {
  106. dates := strings.Split(CreateOn, ",")
  107. if len(dates) == 2 {
  108. minDate := dates[0]
  109. maxDate := dates[1]
  110. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  111. }
  112. }
  113. if SubmitOn != "" {
  114. dates := strings.Split(SubmitOn, ",")
  115. if len(dates) == 2 {
  116. minDate := dates[0]
  117. maxDate := dates[1]
  118. where = where + " and SubmitOn>='" + minDate + "' and SubmitOn<='" + maxDate + "'"
  119. }
  120. }
  121. svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
  122. var list []oilcatalogsub.OilCatalogSub
  123. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  124. var datainfo DataInfo
  125. datainfo.Items = list
  126. datainfo.CurrentItemCount = total
  127. datainfo.PageIndex = page.CurrentPage
  128. datainfo.ItemsPerPage = page.Size
  129. this.Data["json"] = &datainfo
  130. this.ServeJSON()
  131. }
  132. // @Title 获取字典列表
  133. // @Description get user by token
  134. // @Success 200 {object} map[string]interface{}
  135. // @router /dictlist [get]
  136. func (this *OilCatalogSubController) GetDictList() {
  137. dictList := make(map[string]interface{})
  138. //dictSvc := items.GetItemsService(utils.DBE)
  139. userSvc := baseUser.GetBaseUserService(utils.DBE)
  140. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  141. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", this.User.AccCode)
  142. var userEntity userRole.Base_User
  143. userSvc.GetEntityById(this.User.Id, &userEntity)
  144. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId(this.User.AccCode, userEntity.Departmentid)
  145. //var dictCustomer []svccustomer.Customer
  146. //customerSvc.GetEntitysByWhere(this.User.AccCode + CustomerName, "", &dictCustomer)
  147. //dictList["EntrustCorp"] = &dictCustomer
  148. var datainfo DataInfo
  149. datainfo.Items = dictList
  150. this.Data["json"] = &datainfo
  151. this.ServeJSON()
  152. }
  153. // @Title 获取实体
  154. // @Description 获取实体
  155. // @Success 200 {object} oilcatalogsub.OilCatalogSub
  156. // @router /get/:id [get]
  157. func (this *OilCatalogSubController) GetEntity() {
  158. Id := this.Ctx.Input.Param(":id")
  159. var model oilcatalogsub.OilCatalogSub
  160. svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
  161. svc.GetEntityByIdBytbl(OilCatalogSubName, Id, &model)
  162. this.Data["json"] = &model
  163. this.ServeJSON()
  164. }
  165. // @Title 添加
  166. // @Description 新增
  167. // @Param body body oilcatalogsub.OilCatalogSub
  168. // @Success 200 {object} controllers.Request
  169. // @router /add [post]
  170. func (this *OilCatalogSubController) AddEntity() {
  171. var model oilcatalogsub.OilCatalogSub
  172. var jsonBlob = this.Ctx.Input.RequestBody
  173. svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
  174. json.Unmarshal(jsonBlob, &model)
  175. model.Status = "0"
  176. model.CreateOn = time.Now()
  177. model.CreateBy = this.User.Realname
  178. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  179. _, err := svc.InsertEntityBytbl(OilCatalogSubName, &model)
  180. var errinfo ErrorDataInfo
  181. if err == nil {
  182. //新增
  183. errinfo.Message = "添加成功!"
  184. errinfo.Code = 0
  185. errinfo.Item = model.Id
  186. this.Data["json"] = &errinfo
  187. this.ServeJSON()
  188. } else {
  189. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  190. errinfo.Code = -1
  191. this.Data["json"] = &errinfo
  192. this.ServeJSON()
  193. }
  194. }
  195. // @Title 修改实体
  196. // @Description 修改实体
  197. // @Param body body oilcatalogsub.OilCatalogSub
  198. // @Success 200 {object} controllers.Request
  199. // @router /update/:id [post]
  200. func (this *OilCatalogSubController) UpdateEntity() {
  201. id := this.Ctx.Input.Param(":id")
  202. var errinfo ErrorInfo
  203. if id == "" {
  204. errinfo.Message = "操作失败!请求信息不完整"
  205. errinfo.Code = -2
  206. this.Data["json"] = &errinfo
  207. this.ServeJSON()
  208. return
  209. }
  210. var model oilcatalogsub.OilCatalogSub
  211. svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
  212. var jsonBlob = this.Ctx.Input.RequestBody
  213. json.Unmarshal(jsonBlob, &model)
  214. model.ModifiedOn = time.Now()
  215. model.ModifiedBy = this.User.Realname
  216. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  217. cols := []string{
  218. "Id",
  219. "Type",
  220. "Status",
  221. "SubmitterId",
  222. "Submitter",
  223. "DeptId",
  224. "Dept",
  225. "FirstAudit",
  226. "SecondAudit",
  227. "BusinessKey",
  228. "ProcessKey",
  229. "CreateUserId",
  230. "CreateOn",
  231. "CreateBy",
  232. "ModifiedOn",
  233. "ModifiedUserId",
  234. "ModifiedBy",
  235. }
  236. err := svc.UpdateEntityBytbl(OilCatalogSubName, id, &model, cols)
  237. if err == nil {
  238. errinfo.Message = "修改成功!"
  239. errinfo.Code = 0
  240. this.Data["json"] = &errinfo
  241. this.ServeJSON()
  242. } else {
  243. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  244. errinfo.Code = -1
  245. this.Data["json"] = &errinfo
  246. this.ServeJSON()
  247. }
  248. }
  249. // @Title 删除单条信息
  250. // @Description
  251. // @Success 200 {object} ErrorInfo
  252. // @Failure 403 :id 为空
  253. // @router /delete/:Id [delete]
  254. func (this *OilCatalogSubController) DeleteEntity() {
  255. Id := this.Ctx.Input.Param(":Id")
  256. var errinfo ErrorInfo
  257. if Id == "" {
  258. errinfo.Message = "操作失败!请求信息不完整"
  259. errinfo.Code = -2
  260. this.Data["json"] = &errinfo
  261. this.ServeJSON()
  262. return
  263. }
  264. var model oilcatalogsub.OilCatalogSub
  265. svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
  266. err := svc.DeleteEntityById(Id, &model)
  267. if err == nil {
  268. errinfo.Message = "删除成功"
  269. errinfo.Code = 0
  270. this.Data["json"] = &errinfo
  271. this.ServeJSON()
  272. } else {
  273. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  274. errinfo.Code = -1
  275. this.Data["json"] = &errinfo
  276. this.ServeJSON()
  277. }
  278. }
  279. // @Title 删除单条信息
  280. // @Description
  281. // @Success 200 {object} ErrorInfo
  282. // @Failure 403 :id 为空
  283. // @router /deleteentityanditems/:Id [delete]
  284. func (this *OilCatalogSubController) DeleteEntityAndItems() {
  285. Id := this.Ctx.Input.Param(":Id")
  286. var errinfo ErrorInfo
  287. if Id == "" {
  288. errinfo.Message = "操作失败!请求信息不完整"
  289. errinfo.Code = -2
  290. this.Data["json"] = &errinfo
  291. this.ServeJSON()
  292. return
  293. }
  294. var model oilcatalogsub.OilCatalogSub
  295. svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
  296. where := "SubId=" + Id
  297. svc.DeleteEntityBytbl(OilCatalogName, where)
  298. err := svc.DeleteEntityById(Id, &model)
  299. if err == nil {
  300. errinfo.Message = "删除成功"
  301. errinfo.Code = 0
  302. this.Data["json"] = &errinfo
  303. this.ServeJSON()
  304. } else {
  305. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  306. errinfo.Code = -1
  307. this.Data["json"] = &errinfo
  308. this.ServeJSON()
  309. }
  310. }
  311. // @Title 提交审批
  312. // @Description 提交审批
  313. // @Success 200 {object} controllers.Request
  314. // @router /commitaudit/:id [post]
  315. func (this *OilCatalogSubController) CommitAuditEntity() {
  316. Id := this.Ctx.Input.Param(":id")
  317. var entity oilcatalogsub.OilCatalogSub
  318. svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
  319. svc.GetEntityById(Id, &entity)
  320. var catalogsub oilcatalogsub.OilCatalogSub
  321. // 更新主表状态
  322. cols := []string{"Status", "AuditIndex"}
  323. catalogsub.Status = oilcatalogsub.FIRST_TRIAL_STATUS
  324. catalogsub.AuditIndex = entity.AuditIndex + 1
  325. where := "Id=" + Id
  326. svc.UpdateEntityBywheretbl(OilCatalogSubName, &catalogsub, cols, where)
  327. //更新从表状态
  328. var catalog oilcatalog.OilCatalog
  329. cols = []string{"Status"}
  330. catalog.Status = "1"
  331. where = "SubId=" + Id + " and CatalogType=" + entity.Type
  332. svc.UpdateEntityBywheretbl(OilCatalogName, &catalog, cols, where)
  333. //启动工作流
  334. svcActiviti := workflow.GetActivitiService(utils.DBE)
  335. processInstanceId := ""
  336. businessKey := Id + "-" + strconv.Itoa(catalogsub.AuditIndex)
  337. processKey := workflow.OIL_Catalog
  338. processInstanceId = svcActiviti.StartProcess2(processKey, businessKey, this.User.Id, "1", "", "")
  339. //提交到初审
  340. var ActiComplete workflow.ActiCompleteVM
  341. ActiComplete.ProcessKey = processKey
  342. ActiComplete.BusinessKey = businessKey
  343. ActiComplete.UserNames = strconv.Itoa(entity.FirstAudit)
  344. ActiComplete.UserId = this.User.Id
  345. ActiComplete.Result = "1"
  346. ActiComplete.Remarks = entity.Remark
  347. ActiComplete.CallbackUrl = ""
  348. receiveVal := svcActiviti.TaskComplete(ActiComplete)
  349. cols1 := []string{"WorkflowId", "BusinessKey", "ProcessKey"}
  350. catalogsub.BusinessKey = businessKey
  351. catalogsub.ProcessKey = processKey
  352. catalogsub.WorkflowId = processInstanceId
  353. wheresub := "Id=" + Id
  354. svc.UpdateEntityBywheretbl(OilCatalogSubName, &catalogsub, cols1, wheresub)
  355. var audithistoryentity audithistory.Base_AuditHistory
  356. audithistoryentity.EntityId = entity.Id
  357. audithistoryentity.WorkflowId = entity.WorkflowId
  358. audithistoryentity.Process = ActiComplete.ProcessKey
  359. audithistoryentity.BusinessKey = ActiComplete.BusinessKey
  360. audithistoryentity.Type = ""
  361. audithistoryentity.BackStep = entity.Status
  362. audithistoryentity.Index = entity.AuditIndex
  363. audithistoryentity.CreateOn = time.Now()
  364. audithistoryentity.CreateBy = this.User.Realname
  365. audithistoryentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  366. svc.InsertEntity(audithistoryentity)
  367. var errinfo ErrorInfo
  368. if receiveVal == "true" {
  369. errinfo.Message = "提交成功!"
  370. errinfo.Code = 0
  371. this.Data["json"] = &errinfo
  372. this.ServeJSON()
  373. } else {
  374. errinfo.Message = "工作流异常,请联系管理员!"
  375. errinfo.Code = -1
  376. this.Data["json"] = &errinfo
  377. this.ServeJSON()
  378. return
  379. }
  380. }
  381. // @Title 审批
  382. // @Description 审批
  383. // @Param body body suppliercert.OilSupplierCert
  384. // @Success 200 {object} controllers.Request
  385. // @router /auditentity/:id [post]
  386. func (this *OilCatalogSubController) AuditEntity() {
  387. var dataother ShenHeModel
  388. Id := this.Ctx.Input.Param(":id")
  389. var jsonblob = this.Ctx.Input.RequestBody
  390. json.Unmarshal(jsonblob, &dataother)
  391. var entity oilcatalogsub.OilCatalogSub
  392. var catalog oilcatalog.OilCatalog
  393. svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
  394. svc.GetEntityById(Id, &entity)
  395. var errinfo ErrorDataInfo
  396. defer func() { //finally处理失败的异常
  397. if err := recover(); err != nil {
  398. errinfo.Message = "提交失败," + err.(string)
  399. errinfo.Code = -1
  400. this.Data["json"] = &errinfo
  401. this.ServeJSON()
  402. } else {
  403. //返回正确结果
  404. errinfo.Message = "审核提交成功"
  405. errinfo.Code = 0
  406. this.Data["json"] = &errinfo
  407. this.ServeJSON()
  408. }
  409. }()
  410. //remarks := ""
  411. status := ""
  412. backstatus := "0"
  413. var userIds string
  414. if entity.Status == oilcatalogsub.FIRST_TRIAL_STATUS {
  415. userIds = utils.ToStr(entity.SecondAudit)
  416. status = oilcatalogsub.SECOND_TRIAL_STATUS
  417. backstatus = oilcatalogsub.NOPASS_STATUS
  418. } else if entity.Status == oilcatalogsub.SECOND_TRIAL_STATUS {
  419. backstatus = oilcatalogsub.NO_SECOND_TRIAL_STATUS
  420. status = oilcatalogsub.CENT_AUDIT_STATUS
  421. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  422. topid := paramSvc.GetBaseparameterMessage("", "paramset", "CENT_AUDIT")
  423. var userlist []userRole.Base_User
  424. var setting auditsetting.Base_OilAuditSetting
  425. usvc := userRole.GetUserService(utils.DBE)
  426. where := "AuditStepCode='" + workflow.PROF_REGULATION + "'"
  427. usvc.GetEntity(&setting, where)
  428. ids := usvc.GetUserIdsByRoleId(strconv.Itoa(setting.RoleId))
  429. tempstr := strings.Join(ids, ",")
  430. uids := strings.Replace(tempstr, "uid_", "", -1)
  431. uids = strings.Trim(uids, ",")
  432. if uids != "" {
  433. where := "Id in (" + uids + ")" + " and UnitId=" + topid
  434. usvc.GetEntities(&userlist, where)
  435. }
  436. for _, tmpUser := range userlist {
  437. userIds += strconv.Itoa(tmpUser.Id) + ","
  438. }
  439. userIds = strings.Trim(userIds, ",")
  440. } else if entity.Status == oilcatalogsub.CENT_AUDIT_STATUS {
  441. userIds = this.User.Id
  442. status = oilcatalogsub.ALL_PASE_STATUS
  443. backstatus = oilcatalogsub.NO_CENT_AUDIT_STATUS
  444. }
  445. svcActiviti := workflow.GetActivitiService(utils.DBE)
  446. var ActiComplete workflow.ActiCompleteVM
  447. ActiComplete.ProcessKey = entity.ProcessKey
  448. ActiComplete.BusinessKey = entity.BusinessKey
  449. ActiComplete.UserNames = userIds
  450. ActiComplete.UserId = this.User.Id
  451. ActiComplete.Remarks = dataother.AuditorRemark
  452. ActiComplete.CallbackUrl = ""
  453. if dataother.SuccessStatus == 1 {
  454. ActiComplete.Result = "1"
  455. receiveVal := svcActiviti.TaskComplete(ActiComplete)
  456. if receiveVal == "true" {
  457. // 更新主表状态
  458. if entity.Status == oilcatalogsub.CENT_AUDIT_STATUS {
  459. catalog.Status = "2"
  460. } else {
  461. catalog.Status = "1"
  462. }
  463. entity.Status = status
  464. cols := []string{
  465. "Status",
  466. }
  467. svc.UpdateEntityByIdCols(Id, &entity, cols)
  468. // 从表状态
  469. where := "SubId=" + Id + " and CatalogType=" + entity.Type
  470. svc.UpdateEntityBywheretbl(OilCatalogName, &catalog, cols, where)
  471. errinfo.Message = "提交成功!"
  472. errinfo.Code = 0
  473. this.Data["json"] = &errinfo
  474. this.ServeJSON()
  475. } else {
  476. errinfo.Message = "工作流异常,请联系管理员!"
  477. errinfo.Code = -1
  478. this.Data["json"] = &errinfo
  479. this.ServeJSON()
  480. return
  481. }
  482. } else {
  483. ActiComplete.Result = "0"
  484. receiveVal := svcActiviti.TaskComplete(ActiComplete)
  485. if receiveVal == "true" {
  486. // 更新主表状态
  487. entity.Status = backstatus
  488. cols := []string{
  489. "Status",
  490. }
  491. svc.UpdateEntityByIdCols(Id, entity, cols)
  492. // 从表状态
  493. catalog.Status = "0"
  494. where := "SubId=" + Id + " and CatalogType=" + entity.Type
  495. svc.UpdateEntityBywheretbl(OilCatalogName, &catalog, cols, where)
  496. errinfo.Message = "提交成功!"
  497. errinfo.Code = 0
  498. this.Data["json"] = &errinfo
  499. this.ServeJSON()
  500. } else {
  501. errinfo.Message = "工作流异常,请联系管理员!"
  502. errinfo.Code = -1
  503. this.Data["json"] = &errinfo
  504. this.ServeJSON()
  505. return
  506. }
  507. }
  508. }