report_approve.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. package report_approve
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. )
  10. type ReportApprove struct {
  11. ReportApproveId int `gorm:"primaryKey;column:report_approve_id;type:int(10) unsigned;not null"` // 审批ID
  12. ReportType int `gorm:"column:report_type;type:tinyint(4) unsigned;not null;default:0"` // 报告类型:1-中文研报;2-英文研报;3-智能研报
  13. ReportId int `gorm:"index:idx_report_id;column:report_id;type:int(10) unsigned;not null;default:0"` // 报告Id
  14. ReportTitle string `gorm:"column:report_title;type:varchar(255);not null;default:''"` // 报告标题
  15. ClassifyFirstId int `gorm:"column:classify_first_id;type:int(10) unsigned;not null;default:0"` // 一级分类Id
  16. ClassifySecondId int `gorm:"column:classify_second_id;type:int(10) unsigned;not null;default:0"` // 二级分类Id
  17. State int `gorm:"column:state;type:tinyint(4) unsigned;not null;default:0"` // 审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回
  18. FlowId int `gorm:"column:flow_id;type:int(10) unsigned;not null;default:0"` // 审批流Id
  19. FlowVersion int `gorm:"column:flow_version;type:int(10) unsigned;not null;default:0"` // 审批流版本
  20. StartNodeId int `gorm:"column:start_node_id;type:int(10) unsigned;not null;default:0"` // 开始节点Id
  21. CurrNodeId int `gorm:"column:curr_node_id;type:int(10) unsigned;not null;default:0"` // 当前节点Id
  22. ApplyUserId int `gorm:"index:idx_approve_user_id;column:apply_user_id;type:int(10) unsigned;not null;default:0"` // 申请人Id
  23. ApplyUserName string `gorm:"column:apply_user_name;type:varchar(128);not null;default:''"` // 申请人姓名
  24. ApproveRemark string `gorm:"column:approve_remark;type:varchar(255);not null;default:''"` // 审批备注
  25. ApproveTime time.Time `gorm:"column:approve_time;type:datetime"` // 审批时间
  26. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  27. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间
  28. ClassifyThirdId int `gorm:"column:classify_third_id;type:int(10) unsigned;default:0"` // 三级分类Id
  29. }
  30. var ReportApproveCols = struct {
  31. ReportApproveId string
  32. ReportType string
  33. ReportId string
  34. ReportTitle string `description:"报告标题"`
  35. ClassifyFirstId string `description:"一级分类ID"`
  36. ClassifySecondId string `description:"二级分类ID"`
  37. ClassifyThirdId string `description:"三级分类ID"`
  38. State string
  39. FlowId string
  40. FlowVersion string
  41. StartNodeId string
  42. CurrNodeId string
  43. ApplyUserId string `description:"申请人ID"`
  44. ApplyUserName string `description:"申请人姓名"`
  45. ApproveRemark string `description:"审批备注"`
  46. ApproveTime string `description:"审批时间"`
  47. CreateTime string
  48. ModifyTime string
  49. }{
  50. ReportApproveId: "report_approve_id",
  51. ReportType: "report_type",
  52. ReportId: "report_id",
  53. ReportTitle: "report_title",
  54. ClassifyFirstId: "classify_first_id",
  55. ClassifySecondId: "classify_second_id",
  56. ClassifyThirdId: "classify_third_id",
  57. State: "state",
  58. FlowId: "flow_id",
  59. FlowVersion: "flow_version",
  60. StartNodeId: "start_node_id",
  61. CurrNodeId: "curr_node_id",
  62. ApplyUserId: "apply_user_id",
  63. ApplyUserName: "apply_user_name",
  64. ApproveRemark: "approve_remark",
  65. ApproveTime: "approve_time",
  66. CreateTime: "create_time",
  67. ModifyTime: "modify_time",
  68. }
  69. func (m *ReportApprove) TableName() string {
  70. return "report_approve"
  71. }
  72. func (m *ReportApprove) PrimaryId() string {
  73. return ReportApproveCols.ReportApproveId
  74. }
  75. func (m *ReportApprove) Create() (err error) {
  76. err = global.DmSQL["rddp"].Create(m).Error
  77. return
  78. }
  79. func (m *ReportApprove) CreateMulti(items []*ReportApprove) (err error) {
  80. if len(items) == 0 {
  81. return
  82. }
  83. err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
  84. return
  85. }
  86. func (m *ReportApprove) Update(cols []string) (err error) {
  87. err = global.DmSQL["rddp"].Select(cols).Updates(m).Error
  88. return
  89. }
  90. func (m *ReportApprove) Del() (err error) {
  91. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  92. err = global.DmSQL["rddp"].Exec(sql, m.ReportApproveId).Error
  93. return
  94. }
  95. func (m *ReportApprove) MultiDel(menuIds []int) (err error) {
  96. if len(menuIds) == 0 {
  97. return
  98. }
  99. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  100. err = global.DmSQL["rddp"].Exec(sql, menuIds).Error
  101. return
  102. }
  103. func (m *ReportApprove) GetItemById(id int) (item *ReportApprove, err error) {
  104. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  105. err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
  106. return
  107. }
  108. func (m *ReportApprove) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *ReportApprove, err error) {
  109. order := ``
  110. if orderRule != "" {
  111. order = ` ORDER BY ` + orderRule
  112. }
  113. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  114. err = global.DmSQL["rddp"].Raw(sql, pars).First(&item).Error
  115. return
  116. }
  117. func (m *ReportApprove) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  118. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  119. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  120. return
  121. }
  122. func (m *ReportApprove) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ReportApprove, err error) {
  123. fields := strings.Join(fieldArr, ",")
  124. if len(fieldArr) == 0 {
  125. fields = `*`
  126. }
  127. order := `ORDER BY create_time DESC`
  128. if orderRule != "" {
  129. order = ` ORDER BY ` + orderRule
  130. }
  131. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  132. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  133. return
  134. }
  135. func (m *ReportApprove) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*ReportApprove, err error) {
  136. fields := strings.Join(fieldArr, ",")
  137. if len(fieldArr) == 0 {
  138. fields = `*`
  139. }
  140. order := `ORDER BY create_time DESC`
  141. if orderRule != "" {
  142. order = ` ORDER BY ` + orderRule
  143. }
  144. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  145. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  146. return
  147. }
  148. // ReportApproveItem 报告审批信息
  149. type ReportApproveItem struct {
  150. ReportApproveId int `description:"审批ID"`
  151. ReportApproveRecordId int `description:"审批记录ID"`
  152. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  153. ReportId int `description:"报告ID"`
  154. ReportTitle string `description:"报告标题"`
  155. ReportClassify string `description:"报告分类"`
  156. ClassifyFirstId int `description:"一级分类ID"`
  157. ClassifySecondId int `description:"二级分类ID"`
  158. ClassifyThirdId int `description:"三级级分类ID"`
  159. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  160. RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
  161. FlowId int `description:"审批流ID"`
  162. FlowVersion int `description:"审批流版本"`
  163. StartNodeId int `description:"开始节点ID"`
  164. CurrNodeId int `description:"当前节点ID"`
  165. ApplyUserId int `description:"申请人ID"`
  166. ApplyUserName string `description:"申请人姓名"`
  167. ApproveRemark string `description:"审批备注"`
  168. ApproveTime string `description:"审批时间"`
  169. HandleTime string `description:"处理时间"`
  170. CreateTime string `description:"创建时间"`
  171. ModifyTime string `description:"修改时间"`
  172. DetailImgUrl string `description:"报告详情长图地址"`
  173. DetailPdfUrl string `description:"报告详情PDF地址"`
  174. }
  175. // FormatReportApproveOrm2Item 格式化报告审批
  176. func FormatReportApproveOrm2Item(origin *ReportApproveItemOrm) (item *ReportApproveItem) {
  177. item = new(ReportApproveItem)
  178. if origin == nil {
  179. return
  180. }
  181. item.ReportApproveId = origin.ReportApproveId
  182. item.ReportApproveRecordId = origin.ReportApproveRecordId
  183. item.ReportType = origin.ReportType
  184. item.ReportId = origin.ReportId
  185. item.ReportTitle = origin.ReportTitle
  186. item.ClassifyFirstId = origin.ClassifyFirstId
  187. item.ClassifySecondId = origin.ClassifySecondId
  188. item.ClassifyThirdId = origin.ClassifyThirdId
  189. item.State = origin.State
  190. item.RecordState = origin.RecordState
  191. item.FlowId = origin.FlowId
  192. item.FlowVersion = origin.FlowVersion
  193. item.StartNodeId = origin.StartNodeId
  194. item.CurrNodeId = origin.CurrNodeId
  195. item.ApplyUserId = origin.ApplyUserId
  196. item.ApplyUserName = origin.ApplyUserName
  197. item.ApproveRemark = origin.ApproveRemark
  198. item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
  199. item.HandleTime = utils.TimeTransferString(utils.FormatDateTime, origin.HandleTime)
  200. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  201. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  202. return
  203. }
  204. // ReportApproveListReq 审批列表请求体
  205. type ReportApproveListReq struct {
  206. PageSize int `form:"PageSize"`
  207. CurrentIndex int `form:"CurrentIndex"`
  208. ListType int `form:"ListType" description:"列表类型:1-待处理;2-已处理;3-我发起的"`
  209. ReportType int `form:"ReportType" description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  210. ClassifyFirstId int `form:"ClassifyFirstId" description:"一级分类ID"`
  211. ClassifySecondId int `form:"ClassifySecondId" description:"二级分类ID"`
  212. ClassifyThirdId int `form:"ClassifyThirdId" description:"三级级分类ID"`
  213. Keyword string `form:"Keyword" description:"关键词:报告标题"`
  214. ApproveState int `form:"ApproveState" description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  215. TimeType int `form:"TimeType" description:"时间类型:1-提交时间;2-处理时间;3-审批时间"`
  216. StartTime string `form:"StartTime" description:"开始时间"`
  217. EndTime string `form:"EndTime" description:"结束时间"`
  218. SortField int `form:"SortField" description:"排序字段:1-提交时间;2-处理时间;3-审批时间"`
  219. SortRule int `form:"SortRule" description:"排序方式: 1-正序; 2-倒序(默认)"`
  220. }
  221. // ReportApproveListResp 审批列表响应体
  222. type ReportApproveListResp struct {
  223. List []*ReportApproveItem
  224. Paging *paging.PagingItem `description:"分页数据"`
  225. }
  226. type ReportApproveItemOrm struct {
  227. ReportApproveId int `description:"审批ID"`
  228. ReportApproveRecordId int `description:"审批记录ID"`
  229. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  230. ReportId int `description:"报告ID"`
  231. ReportTitle string `description:"报告标题"`
  232. ClassifyFirstId int `description:"一级分类ID"`
  233. ClassifySecondId int `description:"二级分类ID"`
  234. ClassifyThirdId int `description:"三级级分类ID"`
  235. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  236. RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
  237. FlowId int `description:"审批流ID"`
  238. FlowVersion int `description:"审批流版本"`
  239. StartNodeId int `description:"开始节点ID"`
  240. CurrNodeId int `description:"当前节点ID"`
  241. ApplyUserId int `description:"申请人ID"`
  242. ApplyUserName string `description:"申请人姓名"`
  243. ApproveRemark string `description:"审批备注"`
  244. ApproveTime time.Time `description:"审批时间"`
  245. HandleTime time.Time `description:"处理时间"`
  246. CreateTime time.Time `description:"创建时间"`
  247. ModifyTime time.Time `description:"修改时间"`
  248. NodeState int `description:"当前节点审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回" json:"-"`
  249. NodeApproveTime time.Time `description:"当前节点审批时间" json:"-"`
  250. }
  251. // GetApprovingReportApproveCount 获取待处理的审批分页列表总数
  252. func GetApprovingReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  253. base := fmt.Sprintf(`SELECT a.report_approve_record_id
  254. FROM report_approve_record AS a
  255. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id AND a.node_id = b.curr_node_id
  256. WHERE 1 = 1 %s`, cond)
  257. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  258. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  259. return
  260. }
  261. // GetApprovingReportApprovePageList 获取待处理的审批列表-分页
  262. func GetApprovingReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  263. order := `ORDER BY a.create_time DESC`
  264. if orderRule != "" {
  265. order = ` ORDER BY ` + orderRule
  266. }
  267. sql := fmt.Sprintf(`SELECT a.report_approve_record_id, a.state AS record_state, b.*
  268. FROM report_approve_record AS a
  269. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id AND a.node_id = b.curr_node_id
  270. WHERE 1 = 1 %s %s
  271. LIMIT ?,?`, cond, order)
  272. pars = append(pars, startSize, pageSize)
  273. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  274. return
  275. }
  276. // GetApprovedReportApproveCount 获取已处理的审批分页列表总数
  277. func GetApprovedReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  278. base := fmt.Sprintf(`SELECT a.report_approve_record_id
  279. FROM report_approve_record AS a
  280. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
  281. WHERE 1 = 1 %s`, cond)
  282. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  283. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  284. return
  285. }
  286. // GetApprovedReportApprovePageList 获取已处理的审批列表-分页
  287. func GetApprovedReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  288. order := `ORDER BY a.create_time DESC`
  289. if orderRule != "" {
  290. order = ` ORDER BY ` + orderRule
  291. }
  292. sql := fmt.Sprintf(`SELECT a.report_approve_record_id, a.node_state AS record_state,a.node_state,a.node_approve_time, a.node_approve_time AS handle_time, b.*
  293. FROM report_approve_record AS a
  294. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
  295. WHERE 1 = 1 %s %s
  296. LIMIT ?,?`, cond, order)
  297. pars = append(pars, startSize, pageSize)
  298. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  299. return
  300. }
  301. // GetApplyReportApproveCount 获取我发起的审批分页列表总数
  302. func GetApplyReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  303. base := fmt.Sprintf(`SELECT a.* FROM report_approve AS a WHERE 1 = 1 %s`, cond)
  304. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  305. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  306. return
  307. }
  308. // GetApplyReportApprovePageList 获取我发起的审批列表-分页
  309. func GetApplyReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  310. order := `ORDER BY a.create_time DESC`
  311. if orderRule != "" {
  312. order = ` ORDER BY ` + orderRule
  313. }
  314. sql := fmt.Sprintf(`SELECT a.* FROM report_approve AS a WHERE 1 = 1 %s %s LIMIT ?,?`, cond, order)
  315. pars = append(pars, startSize)
  316. pars = append(pars, pageSize)
  317. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  318. return
  319. }
  320. // ReportApproveDetail 审批详情信息
  321. type ReportApproveDetail struct {
  322. Report *ReportApproveDetailReport `description:"报告信息"`
  323. Approve *ReportApproveDetailItem `description:"审批信息"`
  324. ApproveFlowNodes []*ReportApproveDetailNodes `description:"审批节点信息"`
  325. }
  326. // ReportApproveDetailItem 审批详情-审批信息
  327. type ReportApproveDetailItem struct {
  328. ReportApproveId int `description:"审批ID"`
  329. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  330. FlowId int `description:"审批流ID"`
  331. FlowVersion int `description:"审批流版本"`
  332. StartNodeId int `description:"开始节点ID"`
  333. CurrNodeId int `description:"当前节点ID"`
  334. ApplyUserId int `description:"申请人ID"`
  335. ApplyUserName string `description:"申请人姓名"`
  336. ApproveTime string `description:"审批时间"`
  337. CreateTime string `description:"创建时间"`
  338. ModifyTime string `description:"修改时间"`
  339. }
  340. // ReportApproveDetailReport 审批详情-报告信息
  341. type ReportApproveDetailReport struct {
  342. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  343. ReportId int `description:"报告ID"`
  344. ReportTitle string `description:"报告标题"`
  345. ReportCode string `description:"报告code"`
  346. ReportClassify string `description:"报告分类"`
  347. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  348. }
  349. // CreateApproveAndRecord 新增审批和记录
  350. func (m *ReportApprove) CreateApproveAndRecord(approveItem *ReportApprove, recordItems []*ReportApproveRecord) (err error) {
  351. if approveItem == nil {
  352. err = fmt.Errorf("approve is nil")
  353. return
  354. }
  355. tx := global.DmSQL["data"].Begin()
  356. defer func() {
  357. if err != nil {
  358. _ = tx.Rollback()
  359. return
  360. }
  361. _ = tx.Commit()
  362. }()
  363. e := tx.Create(approveItem).Error
  364. if e != nil {
  365. err = fmt.Errorf("insert approve err: %v", e)
  366. return
  367. }
  368. if len(recordItems) > 0 {
  369. for _, v := range recordItems {
  370. v.ReportApproveId = approveItem.ReportApproveId
  371. }
  372. e = tx.CreateInBatches(recordItems, utils.MultiAddNum).Error
  373. if e != nil {
  374. err = fmt.Errorf("insert records err: %v", e)
  375. return
  376. }
  377. }
  378. return
  379. }
  380. // ReportApprovePassReq 审批通过请求体
  381. type ReportApprovePassReq struct {
  382. ReportApproveId int `description:"审批ID"`
  383. ReportUrl string `description:"报告URL"`
  384. }
  385. // ReportApproveRefuseReq 审批驳回请求体
  386. type ReportApproveRefuseReq struct {
  387. ReportApproveId int `description:"审批ID"`
  388. ApproveRemark string `description:"驳回理由"`
  389. }
  390. // ReportApproveCancelReq 撤销审批请求体
  391. type ReportApproveCancelReq struct {
  392. ReportApproveId int `description:"审批ID"`
  393. }
  394. // ReportApproveCheckApproveOpenReq 校验分类是否打开审批请求体
  395. type ReportApproveCheckApproveOpenReq struct {
  396. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  397. ClassifyFirstId int `description:"一级分类ID"`
  398. ClassifySecondId int `description:"二级分类ID"`
  399. ClassifyThirdId int `description:"三级分类ID"`
  400. }