report_approve.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. type ReportApproveItem struct {
  149. ReportApproveId int `description:"审批ID"`
  150. ReportApproveRecordId int `description:"审批记录ID"`
  151. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  152. ReportId int `description:"报告ID"`
  153. ReportTitle string `description:"报告标题"`
  154. ReportClassify string `description:"报告分类"`
  155. ClassifyFirstId int `description:"一级分类ID"`
  156. ClassifySecondId int `description:"二级分类ID"`
  157. ClassifyThirdId int `description:"三级级分类ID"`
  158. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  159. RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
  160. FlowId int `description:"审批流ID"`
  161. FlowVersion int `description:"审批流版本"`
  162. StartNodeId int `description:"开始节点ID"`
  163. CurrNodeId int `description:"当前节点ID"`
  164. ApplyUserId int `description:"申请人ID"`
  165. ApplyUserName string `description:"申请人姓名"`
  166. ApproveRemark string `description:"审批备注"`
  167. ApproveTime string `description:"审批时间"`
  168. HandleTime string `description:"处理时间"`
  169. CreateTime string `description:"创建时间"`
  170. ModifyTime string `description:"修改时间"`
  171. DetailImgUrl string `description:"报告详情长图地址"`
  172. DetailPdfUrl string `description:"报告详情PDF地址"`
  173. }
  174. func FormatReportApproveOrm2Item(origin *ReportApproveItemOrm) (item *ReportApproveItem) {
  175. item = new(ReportApproveItem)
  176. if origin == nil {
  177. return
  178. }
  179. item.ReportApproveId = origin.ReportApproveId
  180. item.ReportApproveRecordId = origin.ReportApproveRecordId
  181. item.ReportType = origin.ReportType
  182. item.ReportId = origin.ReportId
  183. item.ReportTitle = origin.ReportTitle
  184. item.ClassifyFirstId = origin.ClassifyFirstId
  185. item.ClassifySecondId = origin.ClassifySecondId
  186. item.ClassifyThirdId = origin.ClassifyThirdId
  187. item.State = origin.State
  188. item.RecordState = origin.RecordState
  189. item.FlowId = origin.FlowId
  190. item.FlowVersion = origin.FlowVersion
  191. item.StartNodeId = origin.StartNodeId
  192. item.CurrNodeId = origin.CurrNodeId
  193. item.ApplyUserId = origin.ApplyUserId
  194. item.ApplyUserName = origin.ApplyUserName
  195. item.ApproveRemark = origin.ApproveRemark
  196. item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
  197. item.HandleTime = utils.TimeTransferString(utils.FormatDateTime, origin.HandleTime)
  198. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  199. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  200. return
  201. }
  202. type ReportApproveListReq struct {
  203. PageSize int `form:"PageSize"`
  204. CurrentIndex int `form:"CurrentIndex"`
  205. ListType int `form:"ListType" description:"列表类型:1-待处理;2-已处理;3-我发起的"`
  206. ReportType int `form:"ReportType" description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  207. ClassifyFirstId int `form:"ClassifyFirstId" description:"一级分类ID"`
  208. ClassifySecondId int `form:"ClassifySecondId" description:"二级分类ID"`
  209. ClassifyThirdId int `form:"ClassifyThirdId" description:"三级级分类ID"`
  210. Keyword string `form:"Keyword" description:"关键词:报告标题"`
  211. ApproveState int `form:"ApproveState" description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  212. TimeType int `form:"TimeType" description:"时间类型:1-提交时间;2-处理时间;3-审批时间"`
  213. StartTime string `form:"StartTime" description:"开始时间"`
  214. EndTime string `form:"EndTime" description:"结束时间"`
  215. SortField int `form:"SortField" description:"排序字段:1-提交时间;2-处理时间;3-审批时间"`
  216. SortRule int `form:"SortRule" description:"排序方式: 1-正序; 2-倒序(默认)"`
  217. }
  218. type ReportApproveListResp struct {
  219. List []*ReportApproveItem
  220. Paging *paging.PagingItem `description:"分页数据"`
  221. }
  222. type ReportApproveItemOrm struct {
  223. ReportApproveId int `description:"审批ID"`
  224. ReportApproveRecordId int `description:"审批记录ID"`
  225. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  226. ReportId int `description:"报告ID"`
  227. ReportTitle string `description:"报告标题"`
  228. ClassifyFirstId int `description:"一级分类ID"`
  229. ClassifySecondId int `description:"二级分类ID"`
  230. ClassifyThirdId int `description:"三级级分类ID"`
  231. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  232. RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
  233. FlowId int `description:"审批流ID"`
  234. FlowVersion int `description:"审批流版本"`
  235. StartNodeId int `description:"开始节点ID"`
  236. CurrNodeId int `description:"当前节点ID"`
  237. ApplyUserId int `description:"申请人ID"`
  238. ApplyUserName string `description:"申请人姓名"`
  239. ApproveRemark string `description:"审批备注"`
  240. ApproveTime time.Time `description:"审批时间"`
  241. HandleTime time.Time `description:"处理时间"`
  242. CreateTime time.Time `description:"创建时间"`
  243. ModifyTime time.Time `description:"修改时间"`
  244. NodeState int `description:"当前节点审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回" json:"-"`
  245. NodeApproveTime time.Time `description:"当前节点审批时间" json:"-"`
  246. }
  247. func GetApprovingReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  248. base := fmt.Sprintf(`SELECT a.report_approve_record_id
  249. FROM report_approve_record AS a
  250. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id AND a.node_id = b.curr_node_id
  251. WHERE 1 = 1 %s`, cond)
  252. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  253. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  254. return
  255. }
  256. func GetApprovingReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  257. order := `ORDER BY a.create_time DESC`
  258. if orderRule != "" {
  259. order = ` ORDER BY ` + orderRule
  260. }
  261. sql := fmt.Sprintf(`SELECT a.report_approve_record_id, a.state AS record_state, b.*
  262. FROM report_approve_record AS a
  263. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id AND a.node_id = b.curr_node_id
  264. WHERE 1 = 1 %s %s
  265. LIMIT ?,?`, cond, order)
  266. pars = append(pars, startSize, pageSize)
  267. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  268. return
  269. }
  270. func GetApprovedReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  271. base := fmt.Sprintf(`SELECT a.report_approve_record_id
  272. FROM report_approve_record AS a
  273. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
  274. WHERE 1 = 1 %s`, cond)
  275. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  276. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  277. return
  278. }
  279. func GetApprovedReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  280. order := `ORDER BY a.create_time DESC`
  281. if orderRule != "" {
  282. order = ` ORDER BY ` + orderRule
  283. }
  284. 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.*
  285. FROM report_approve_record AS a
  286. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
  287. WHERE 1 = 1 %s %s
  288. LIMIT ?,?`, cond, order)
  289. pars = append(pars, startSize, pageSize)
  290. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  291. return
  292. }
  293. func GetApplyReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  294. base := fmt.Sprintf(`SELECT a.* FROM report_approve AS a WHERE 1 = 1 %s`, cond)
  295. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  296. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  297. return
  298. }
  299. func GetApplyReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  300. order := `ORDER BY a.create_time DESC`
  301. if orderRule != "" {
  302. order = ` ORDER BY ` + orderRule
  303. }
  304. sql := fmt.Sprintf(`SELECT a.* FROM report_approve AS a WHERE 1 = 1 %s %s LIMIT ?,?`, cond, order)
  305. pars = append(pars, startSize)
  306. pars = append(pars, pageSize)
  307. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  308. return
  309. }
  310. type ReportApproveDetail struct {
  311. Report *ReportApproveDetailReport `description:"报告信息"`
  312. Approve *ReportApproveDetailItem `description:"审批信息"`
  313. ApproveFlowNodes []*ReportApproveDetailNodes `description:"审批节点信息"`
  314. }
  315. type ReportApproveDetailItem struct {
  316. ReportApproveId int `description:"审批ID"`
  317. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  318. FlowId int `description:"审批流ID"`
  319. FlowVersion int `description:"审批流版本"`
  320. StartNodeId int `description:"开始节点ID"`
  321. CurrNodeId int `description:"当前节点ID"`
  322. ApplyUserId int `description:"申请人ID"`
  323. ApplyUserName string `description:"申请人姓名"`
  324. ApproveTime string `description:"审批时间"`
  325. CreateTime string `description:"创建时间"`
  326. ModifyTime string `description:"修改时间"`
  327. }
  328. type ReportApproveDetailReport struct {
  329. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  330. ReportId int `description:"报告ID"`
  331. ReportTitle string `description:"报告标题"`
  332. ReportCode string `description:"报告code"`
  333. ReportClassify string `description:"报告分类"`
  334. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  335. }
  336. func (m *ReportApprove) CreateApproveAndRecord(approveItem *ReportApprove, recordItems []*ReportApproveRecord) (err error) {
  337. if approveItem == nil {
  338. err = fmt.Errorf("approve is nil")
  339. return
  340. }
  341. tx := global.DmSQL["data"].Begin()
  342. defer func() {
  343. if err != nil {
  344. _ = tx.Rollback()
  345. return
  346. }
  347. _ = tx.Commit()
  348. }()
  349. e := tx.Create(approveItem).Error
  350. if e != nil {
  351. err = fmt.Errorf("insert approve err: %v", e)
  352. return
  353. }
  354. if len(recordItems) > 0 {
  355. for _, v := range recordItems {
  356. v.ReportApproveId = approveItem.ReportApproveId
  357. }
  358. e = tx.CreateInBatches(recordItems, utils.MultiAddNum).Error
  359. if e != nil {
  360. err = fmt.Errorf("insert records err: %v", e)
  361. return
  362. }
  363. }
  364. return
  365. }
  366. type ReportApprovePassReq struct {
  367. ReportApproveId int `description:"审批ID"`
  368. ReportUrl string `description:"报告URL"`
  369. }
  370. type ReportApproveRefuseReq struct {
  371. ReportApproveId int `description:"审批ID"`
  372. ApproveRemark string `description:"驳回理由"`
  373. }
  374. type ReportApproveCancelReq struct {
  375. ReportApproveId int `description:"审批ID"`
  376. }
  377. type ReportApproveCheckApproveOpenReq struct {
  378. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  379. ClassifyFirstId int `description:"一级分类ID"`
  380. ClassifySecondId int `description:"二级分类ID"`
  381. ClassifyThirdId int `description:"三级分类ID"`
  382. }