SysWfController.go 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. package partial
  2. import (
  3. "git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
  4. //sysmodel "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
  5. //sysutils "git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
  6. "fmt"
  7. "strconv"
  8. "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
  9. sysmodel "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
  10. "git.qianqiusoft.com/qianqiusoft/light-apiengine/wfclient"
  11. //__import_packages__
  12. )
  13. // _WfInstanceList
  14. // @Title _WfInstanceList
  15. // @Description 分页获取流程实例
  16. // @Param false ""
  17. // @Success 200 {object} models.Account
  18. // @Failure 403 :id is empty
  19. func SysWf_WfInstanceList(c *entitys.CtrlContext) {
  20. page, _ := strconv.Atoi(c.Ctx.DefaultQuery("page", "1"))
  21. rows, _ := strconv.Atoi(c.Ctx.DefaultQuery("rows", "10"))
  22. //page :=c.Ctx.GetInt("page")
  23. //rows :=c.Ctx.GetInt("rows")
  24. sidx := c.Ctx.DefaultQuery("sidx", "")
  25. sord := c.Ctx.DefaultQuery("sord", "")
  26. filter := c.Ctx.Query("filters")
  27. bytess, err := wfclient.NewWFClient(c).FetchWFINstances(page, rows, filter, sidx, sord)
  28. if err == nil {
  29. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  30. //c.Ctx.String(200,"",string(bytess))
  31. } else {
  32. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  33. }
  34. }
  35. // _InstanceStepCurrent
  36. // @Title _InstanceStepCurrent
  37. // @Description 实例当前状态
  38. // @Param instance_id false ""
  39. // @Success 200 {object} models.Account
  40. // @Failure 403 :id is empty
  41. func SysWf_InstanceStepCurrent(c *entitys.CtrlContext) {
  42. instanceId := c.Ctx.Query("instance_id")
  43. bytess, err := wfclient.NewWFClient(c).FetchCurrentStepByLoginUser(instanceId)
  44. if err == nil {
  45. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  46. } else {
  47. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  48. }
  49. }
  50. // _Prerun
  51. // @Title _Prerun
  52. // @Description 运行实例前奏
  53. // @Param choice false ""
  54. // @Param instance_id false ""
  55. // @Success 200 {object} models.Account
  56. // @Failure 403 :id is empty
  57. func SysWf_Prerun(c *entitys.CtrlContext) {
  58. obj := models.WfRunData{}
  59. err := c.Ctx.Bind(&obj)
  60. if err != nil {
  61. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  62. return
  63. }
  64. bytess, err := wfclient.NewWFClient(c).PreRun(obj.InstanceId, obj.Choice)
  65. if err == nil {
  66. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  67. } else {
  68. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  69. }
  70. }
  71. // _Run
  72. // @Title _Run
  73. // @Description 运行实例
  74. // @Param choice false ""
  75. // @Param instance_id false ""
  76. // @Param nextStep false ""
  77. // @Param option false ""
  78. // @Param users false ""
  79. // @Success 200 {object} models.Account
  80. // @Failure 403 :id is empty
  81. func SysWf_Run(c *entitys.CtrlContext) {
  82. obj := models.WfRunData{}
  83. err := c.Ctx.Bind(&obj)
  84. if err != nil {
  85. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  86. return
  87. }
  88. bytess, err := wfclient.NewWFClient(c).Run(obj.InstanceId, obj.Users, obj.Choice, obj.Opinion, obj.NextStep, c)
  89. if err == nil {
  90. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  91. } else {
  92. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  93. }
  94. }
  95. // _WfDefinesTag
  96. // @Title _WfDefinesTag
  97. // @Description 根据tag获取工作流事项
  98. // @Param tag false ""
  99. // @Success 200 {object} models.Account
  100. // @Failure 403 :id is empty
  101. func SysWf_WfDefinesTag(c *entitys.CtrlContext) {
  102. tag := c.Ctx.Query("tag")
  103. bytess, err := wfclient.NewWFClient(c).FetchDefinesByTag(tag)
  104. if err == nil {
  105. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  106. } else {
  107. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  108. }
  109. }
  110. // _WfDefineForm
  111. // @Title _WfDefineForm
  112. // @Description 根据表单名称获取表单
  113. // @Param form false ""
  114. // @Success 200 {object} models.Account
  115. // @Failure 403 :id is empty
  116. func SysWf_WfDefineForm(c *entitys.CtrlContext) {
  117. form := c.Ctx.Query("form")
  118. ret := __none_func_sys_wf__(form)
  119. if ret {
  120. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", nil})
  121. } else {
  122. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  123. }
  124. }
  125. // _Recall
  126. // @Title _Recall
  127. // @Description 撤回
  128. // @Param instance_id false ""
  129. // @Success 200 {object} models.Account
  130. // @Failure 403 :id is empty
  131. func SysWf_Recall(c *entitys.CtrlContext) {
  132. obj := models.WfRunData{}
  133. err := c.Ctx.Bind(&obj)
  134. if err != nil {
  135. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  136. return
  137. }
  138. bytess, err := wfclient.NewWFClient(c).Recall(obj.InstanceId)
  139. if err == nil {
  140. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  141. } else {
  142. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  143. }
  144. }
  145. // _Interrupt
  146. // @Title _Interrupt
  147. // @Description 终止
  148. // @Param instance_id false ""
  149. // @Success 200 {object} models.Account
  150. // @Failure 403 :id is empty
  151. func SysWf_Interrupt(c *entitys.CtrlContext) {
  152. obj := map[string]interface{}{}
  153. err := c.Ctx.Bind(&obj)
  154. if err != nil {
  155. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  156. return
  157. }
  158. instanceId := fmt.Sprintf("%v", obj["instance_id"])
  159. bytess, err := wfclient.NewWFClient(c).Interrupt(instanceId, obj, c)
  160. if err == nil {
  161. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  162. } else {
  163. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  164. }
  165. }
  166. // _Designer
  167. // @Title _Designer
  168. // @Description 修改流程定义
  169. // @Param define_id false ""
  170. // @Success 200 {object} models.Account
  171. // @Failure 403 :id is empty
  172. func SysWf_Designer(c *entitys.CtrlContext) {
  173. define_id := c.Ctx.Query("define_id")
  174. bytess, err := wfclient.NewWFClient(c).FetchDesignDiagram(define_id)
  175. if err == nil {
  176. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  177. } else {
  178. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  179. }
  180. }
  181. // _DefineSave
  182. // @Title _DefineSave
  183. // @Description 保存流程定义
  184. // @Param define_id false ""
  185. // @Success 200 {object} models.Account
  186. // @Failure 403 :id is empty
  187. func SysWf_DefineSave(c *entitys.CtrlContext) {
  188. PostData := models.WfDefine{}
  189. err := c.Ctx.Bind(&PostData)
  190. bytess, err := wfclient.NewWFClient(c).CreateOrUpdateDefine(PostData.DefineId, PostData.Name, PostData.Descript, PostData.Data, PostData.Form, PostData.Tag, PostData.Code)
  191. if err == nil {
  192. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  193. } else {
  194. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  195. }
  196. }
  197. // _DefineCreate
  198. // @Title _DefineCreate
  199. // @Description 创建流程定义
  200. // @Param false ""
  201. // @Success 200 {object} models.Account
  202. // @Failure 403 :id is empty
  203. func SysWf_DefineCreate(c *entitys.CtrlContext) {
  204. PostData := models.WfDefine{}
  205. err := c.Ctx.Bind(&PostData)
  206. bytess, err := wfclient.NewWFClient(c).CreateOrUpdateDefine(PostData.DefineId, PostData.Name, PostData.Descript, PostData.Data, PostData.Form, PostData.Tag, PostData.Code)
  207. if err == nil {
  208. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  209. } else {
  210. c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
  211. }
  212. }
  213. // _CreateInstance
  214. // @Title _CreateInstance
  215. // @Description 创建流程实例
  216. // @Param false ""
  217. // @Success 200 {object} Account
  218. // @Failure 403 :id is empty
  219. func SysWf_CreateInstance(c *entitys.CtrlContext) {
  220. var InstanceInfo struct {
  221. DefineId string `json:"define_id"`
  222. Name string `json:"name"`
  223. FormData string `json:"form_data"`
  224. }
  225. err := c.Ctx.BindJSON(&InstanceInfo)
  226. if err != nil {
  227. c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
  228. return
  229. }
  230. bytess, err := wfclient.NewWFClient(c).CreateInstance(InstanceInfo.DefineId, InstanceInfo.Name, InstanceInfo.FormData)
  231. if err == nil {
  232. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  233. } else {
  234. c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
  235. }
  236. }
  237. // _Define
  238. // @Title _Define
  239. // @Description 获取流程定义
  240. // @Param define_id string false ""
  241. // @Success 200 {object} Account
  242. // @Failure 403 :id is empty
  243. func SysWf_Define(c *entitys.CtrlContext) {
  244. define_id := c.Ctx.Query("define_id")
  245. bytess, err := wfclient.NewWFClient(c).FetchDefine(define_id)
  246. fmt.Println(string(bytess))
  247. if err == nil {
  248. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  249. } else {
  250. c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
  251. }
  252. }
  253. // _AllDefine
  254. // @Title _AllDefine
  255. // @Description 获取所有流程定义
  256. // @Success 200 {object} Account
  257. // @Failure 403 :id is empty
  258. func SysWf_AllDefine(c *entitys.CtrlContext) {
  259. bytess, err := wfclient.NewWFClient(c).FetchAllDefines()
  260. if err == nil {
  261. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  262. } else {
  263. c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
  264. }
  265. }
  266. // _UpdateIntanceForm
  267. // @Title _UpdateIntanceForm
  268. // @Description 更新流程实例form表单
  269. // @Success 200 {object} Account
  270. // @Failure 403 :id is empty
  271. func SysWf_UpdateIntanceForm(c *entitys.CtrlContext) {
  272. var data struct {
  273. InstanceId string `json:"instance_id"`
  274. FormData string `json:"form_data"`
  275. }
  276. err := c.Ctx.BindJSON(&data)
  277. if err != nil {
  278. c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
  279. return
  280. }
  281. bytess, err := wfclient.NewWFClient(c).UpdateInstanceForm(data.InstanceId, data.FormData)
  282. if err == nil {
  283. c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
  284. } else {
  285. c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), ""})
  286. }
  287. }
  288. func __none_func_sys_wf__(params ...interface{}) bool {
  289. return true
  290. }