seal_approval.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. package controllers
  2. import (
  3. "encoding/json"
  4. contractReq "hongze/hongze_mobile_admin/models/request/contract"
  5. sealResp "hongze/hongze_mobile_admin/models/response/seal"
  6. "hongze/hongze_mobile_admin/models/tables/contract_approval"
  7. "hongze/hongze_mobile_admin/models/tables/contract_approval_record"
  8. contractService "hongze/hongze_mobile_admin/services/contract"
  9. "hongze/hongze_mobile_admin/utils"
  10. "rdluck_tools/paging"
  11. "strconv"
  12. "strings"
  13. )
  14. //用印审批模块
  15. type SealApprovalCommon struct {
  16. BaseAuth
  17. }
  18. // @Title 审批单列表
  19. // @Description 审批单列表接口
  20. // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
  21. // @Param Status query string false "合同状态,枚举值:'待审批','已审批','已驳回','已撤回'"
  22. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  23. // @Param SellerId query string false "选择的销售id"
  24. // @Param Keyword query string false "搜索关键字"
  25. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  26. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  27. // @Success 200 {object} response.ContractApprovalListResp
  28. // @router /list [get]
  29. func (this *SealApprovalCommon) List() {
  30. sysUser := this.AdminWx
  31. //合同类型、产品类型、合同状态、更新时间、所选销售
  32. //关键字:合同编号、客户名称,社会信用码
  33. contractType := this.GetString("ContractType")
  34. status := this.GetString("Status")
  35. productId, _ := this.GetInt("ProductId")
  36. sellerIds := this.GetString("SellerId")
  37. keyword := this.GetString("Keyword")
  38. modifyStartTime := this.GetString("ModifyStartTime")
  39. modifyEndTime := this.GetString("ModifyEndTime")
  40. childCondition := ""
  41. condition := ""
  42. childPars := make([]interface{}, 0)
  43. pars := make([]interface{}, 0)
  44. ////如果不是超管或者合规,那么只能查看自己的合同
  45. //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //权益管理员
  46. // condition += ` AND c.product_id = ? `
  47. // pars = append(pars, 2)
  48. //} else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN { //ficc管理员
  49. // condition += ` AND c.product_id = ? `
  50. // pars = append(pars, 1)
  51. //} else {
  52. // if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  53. // condition += ` AND c.seller_id = ? `
  54. // pars = append(pars, sysUser.AdminId)
  55. // }
  56. //}
  57. condition += ` AND (c.user_id = ? or d.approve_user_id = ?)`
  58. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  59. //合同类型、、更新时间、所选销售
  60. //关键字:合同编号、客户名称,社会信用码
  61. if contractType != "" {
  62. condition += ` AND c.contract_type = ? `
  63. pars = append(pars, contractType)
  64. }
  65. //审批状态
  66. if status != "" {
  67. //childCondition += ` AND status = ? `
  68. //childPars = append(childPars, status)
  69. if status == "已审批" {
  70. condition += ` AND c.status in ("已审批","已驳回") `
  71. } else {
  72. condition += ` AND c.status = ? `
  73. pars = append(pars, status)
  74. }
  75. } else {
  76. //childCondition += ` AND status != "已撤回" `
  77. condition += ` AND c.status not in ("已撤回","待提交") `
  78. }
  79. //产品类型
  80. if productId > 0 {
  81. condition += ` AND c.product_id = ? `
  82. pars = append(pars, productId)
  83. }
  84. //所选销售
  85. if sellerIds != "" {
  86. condition += ` AND c.user_id IN (` + sellerIds + `) `
  87. }
  88. //更新开始时间
  89. //更新开始时间
  90. if modifyStartTime != "" {
  91. condition += ` AND a.modify_time >= ? `
  92. pars = append(pars, modifyStartTime)
  93. }
  94. //更新结束时间
  95. if modifyEndTime != "" {
  96. condition += ` AND a.modify_time <= ? `
  97. pars = append(pars, modifyEndTime)
  98. }
  99. //关键字
  100. if keyword != "" {
  101. condition += ` AND (c.contract_code LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
  102. }
  103. pageSize, _ := this.GetInt("PageSize")
  104. currentIndex, _ := this.GetInt("CurrentIndex")
  105. var startSize int
  106. if pageSize <= 0 {
  107. pageSize = utils.PageSize20
  108. }
  109. if currentIndex <= 0 {
  110. currentIndex = 1
  111. }
  112. startSize = paging.StartIndex(currentIndex, pageSize)
  113. total, err := contract_approval.GetSealApprovalListCount(childCondition, condition, childPars, pars)
  114. if err != nil {
  115. this.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  116. return
  117. }
  118. list, err := contract_approval.GetSealApprovalList(childCondition, condition, childPars, pars, startSize, pageSize)
  119. if err != nil {
  120. this.FailWithMessage("获取审批列表失败!", "获取审批列表失败,Err:"+err.Error())
  121. return
  122. }
  123. if len(list) > 0 {
  124. contractApprovalIdSlice := make([]string, 0)
  125. for i := 0; i < len(list); i++ {
  126. contractApprovalIdSlice = append(contractApprovalIdSlice, strconv.Itoa(list[i].ContractApprovalId))
  127. }
  128. contractApprovalIdStr := strings.Join(contractApprovalIdSlice, ",")
  129. //获取审批流列表数据
  130. contractApprovalRecordList, err := contract_approval_record.GetContractApprovalRecordList(contractApprovalIdStr, sysUser.AdminId)
  131. if err != nil {
  132. this.FailWithMessage("获取审批列表失败!", "获取审批列表失败,Err:"+err.Error())
  133. return
  134. }
  135. contractApprovalRecordMap := make(map[int]*contract_approval_record.ContractApprovalRecord)
  136. for i := 0; i < len(contractApprovalRecordList); i++ {
  137. contractApprovalRecordMap[contractApprovalRecordList[i].ContractApprovalId] = contractApprovalRecordList[i]
  138. }
  139. for i := 0; i < len(list); i++ {
  140. item := list[i]
  141. list[i].StartDateStr = item.StartDate.Format(utils.FormatDate)
  142. list[i].EndDateStr = item.EndDate.Format(utils.FormatDate)
  143. list[i].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
  144. list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
  145. //list[i].ContractInfo = contractDetail
  146. //校验最新审批流数据
  147. if contractApprovalRecord, has := contractApprovalRecordMap[item.ContractApprovalId]; has {
  148. //审批流id
  149. list[i].ContractApprovalRecordId = contractApprovalRecord.ContractApprovalRecordId
  150. //审批时间
  151. list[i].ApproveTime = contractApprovalRecord.ApproveTime
  152. list[i].ApproveTimeStr = contractApprovalRecord.ApproveTime.Format(utils.FormatDateTime)
  153. //判断是否有操作权限
  154. list[i].Status = contractApprovalRecord.Status
  155. //判断是否处于待审批状态
  156. //if contractApprovalRecord.Status == "待审批" {
  157. // //如果不是审批者,那么不能审批操作
  158. // if contractApprovalRecord.NodeType != "check" {
  159. // continue
  160. // }
  161. // //如果没有指定审批人的话
  162. // if contractApprovalRecord.ApproveUserId <= 0 {
  163. // //判断是否与审批角色一致,如果一致,那么允许操作审批
  164. // if contractApprovalRecord.ApproveRoleTypeCode == sysUser.RoleTypeCode {
  165. // list[i].CanApprovalButton = true
  166. // }
  167. // } else if contractApprovalRecord.ApproveUserId == sysUser.AdminId {
  168. // //如果指定审批人就是自己的话,那么操作审批
  169. // list[i].CanApprovalButton = true
  170. // }
  171. //}
  172. }
  173. //合同状态(突然说要改成展示合同状态,那就根据业务需求,改成返回:合同状态咯)
  174. list[i].Status = item.ContractStatus
  175. }
  176. }
  177. page := paging.GetPaging(currentIndex, pageSize, total)
  178. this.OkDetailed(sealResp.SealApprovalListResp{
  179. List: list,
  180. Paging: page,
  181. }, "获取成功")
  182. }
  183. // @Title 驳回审批
  184. // @Description 驳回审批接口
  185. // @Param request body contract.RejectReq true "type json string"
  186. // @Success Ret=200 驳回成功
  187. // @router /reject [post]
  188. func (this *SealApprovalCommon) Reject() {
  189. var req contractReq.RejectReq
  190. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  191. if err != nil {
  192. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  193. return
  194. }
  195. //审批单id编号
  196. contractApprovalId := req.ApprovalId
  197. if contractApprovalId <= 0 {
  198. this.FailWithMessage("请传入审批单编号!", "请传入审批单编号!")
  199. return
  200. }
  201. //审批单详情
  202. approvalInfo, err := contract_approval.GetContractApprovalById(contractApprovalId)
  203. if err != nil {
  204. this.FailWithMessage("获取审批单失败!", "获取审批单失败,Err:"+err.Error())
  205. return
  206. }
  207. //审批流
  208. approvalRecordList, err := contract_approval_record.GetContractApprovalRecordListByContractApprovalIdAndNodeId(contractApprovalId, approvalInfo.CurrNodeId)
  209. if err != nil {
  210. this.FailWithMessage("获取审批失败!", "获取审批失败,Err:"+err.Error())
  211. return
  212. }
  213. var approvalRecord *contract_approval_record.ContractApprovalRecord
  214. for _, tmpApprovalRecord := range approvalRecordList {
  215. if tmpApprovalRecord.NodeType == "check" && tmpApprovalRecord.ApproveUserId == this.AdminWx.AdminId {
  216. approvalRecord = tmpApprovalRecord
  217. }
  218. }
  219. if approvalRecord == nil {
  220. this.FailWithMessage("当前账号没有审批权限", "当前账号没有审批权限")
  221. }
  222. err = contractService.Reject(approvalRecord, this.AdminWx, req.Remark)
  223. if err != nil {
  224. this.FailWithMessage("驳回审批失败!", "驳回审批失败,Err:"+err.Error())
  225. return
  226. }
  227. this.OkWithMessage("驳回成功")
  228. }
  229. // @Title 处理审批单
  230. // @Description 处理审批单
  231. // @Param request body request.ApprovedReq true "type json string"
  232. // @Success Ret=200 申请成功
  233. // @router /approved [post]
  234. func (this *SealApprovalCommon) Approved() {
  235. var req contractReq.ApprovedReq
  236. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  237. if err != nil {
  238. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  239. return
  240. }
  241. //审批单id编号
  242. contractApprovalId := req.ApprovalId
  243. if contractApprovalId <= 0 {
  244. this.FailWithMessage("请传入审批单编号!", "请传入审批单编号!")
  245. return
  246. }
  247. //审批单详情
  248. approvalInfo, err := contract_approval.GetContractApprovalById(contractApprovalId)
  249. if err != nil {
  250. this.FailWithMessage("获取审批单失败!", "获取审批单失败,Err:"+err.Error())
  251. return
  252. }
  253. //审批流
  254. approvalRecordList, err := contract_approval_record.GetContractApprovalRecordListByContractApprovalIdAndNodeId(contractApprovalId, approvalInfo.CurrNodeId)
  255. if err != nil {
  256. this.FailWithMessage("获取审批失败!", "获取审批失败,Err:"+err.Error())
  257. return
  258. }
  259. var approvalRecord *contract_approval_record.ContractApprovalRecord
  260. for _, tmpApprovalRecord := range approvalRecordList {
  261. if tmpApprovalRecord.NodeType == "check" && tmpApprovalRecord.ApproveUserId == this.AdminWx.AdminId {
  262. approvalRecord = tmpApprovalRecord
  263. }
  264. }
  265. if approvalRecord == nil {
  266. this.FailWithMessage("当前账号没有审批权限", "当前账号没有审批权限")
  267. }
  268. err = contractService.Approved(approvalRecord, this.AdminWx, req.Remark)
  269. if err != nil {
  270. this.FailWithMessage("审核失败!", "审核失败,Err:"+err.Error())
  271. return
  272. }
  273. this.OkWithMessage("审核通过")
  274. }