seal_approval.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. sealService "hongze/hongze_mobile_admin/services/seal"
  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} seal.SealApprovalListResp
  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].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
  142. list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
  143. //list[i].ContractInfo = contractDetail
  144. //校验最新审批流数据
  145. if contractApprovalRecord, has := contractApprovalRecordMap[item.ContractApprovalId]; has {
  146. //审批流id
  147. list[i].ContractApprovalRecordId = contractApprovalRecord.ContractApprovalRecordId
  148. //审批时间
  149. list[i].ApproveTime = contractApprovalRecord.ApproveTime
  150. list[i].ApproveTimeStr = contractApprovalRecord.ApproveTime.Format(utils.FormatDateTime)
  151. //判断是否有操作权限
  152. list[i].Status = contractApprovalRecord.Status
  153. //判断是否处于待审批状态
  154. //if contractApprovalRecord.Status == "待审批" {
  155. // //如果不是审批者,那么不能审批操作
  156. // if contractApprovalRecord.NodeType != "check" {
  157. // continue
  158. // }
  159. // //如果没有指定审批人的话
  160. // if contractApprovalRecord.ApproveUserId <= 0 {
  161. // //判断是否与审批角色一致,如果一致,那么允许操作审批
  162. // if contractApprovalRecord.ApproveRoleTypeCode == sysUser.RoleTypeCode {
  163. // list[i].CanApprovalButton = true
  164. // }
  165. // } else if contractApprovalRecord.ApproveUserId == sysUser.AdminId {
  166. // //如果指定审批人就是自己的话,那么操作审批
  167. // list[i].CanApprovalButton = true
  168. // }
  169. //}
  170. }
  171. //合同状态(突然说要改成展示合同状态,那就根据业务需求,改成返回:合同状态咯)
  172. list[i].Status = item.SealStatus
  173. }
  174. }
  175. page := paging.GetPaging(currentIndex, pageSize, total)
  176. this.OkDetailed(sealResp.SealApprovalListResp{
  177. List: list,
  178. Paging: page,
  179. }, "获取成功")
  180. }
  181. // @Title 驳回审批
  182. // @Description 驳回审批接口
  183. // @Param request body contract.RejectReq true "type json string"
  184. // @Success Ret=200 驳回成功
  185. // @router /reject [post]
  186. func (this *SealApprovalCommon) Reject() {
  187. var req contractReq.RejectReq
  188. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  189. if err != nil {
  190. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  191. return
  192. }
  193. //审批单id编号
  194. contractApprovalId := req.ApprovalId
  195. if contractApprovalId <= 0 {
  196. this.FailWithMessage("请传入审批单编号!", "请传入审批单编号!")
  197. return
  198. }
  199. //审批单详情
  200. approvalInfo, err := contract_approval.GetContractApprovalById(contractApprovalId)
  201. if err != nil {
  202. this.FailWithMessage("获取审批单失败!", "获取审批单失败,Err:"+err.Error())
  203. return
  204. }
  205. if approvalInfo.Status != "待审批" {
  206. this.FailWithMessage("当前审批单状态异常,不允许审批", "当前审批单状态异常,不允许审批,审批单状态:"+approvalInfo.Status)
  207. }
  208. //审批流
  209. approvalRecordList, err := contract_approval_record.GetContractApprovalRecordListByContractApprovalIdAndNodeId(contractApprovalId, approvalInfo.CurrNodeId)
  210. if err != nil {
  211. this.FailWithMessage("获取审批失败!", "获取审批失败,Err:"+err.Error())
  212. return
  213. }
  214. var approvalRecord *contract_approval_record.ContractApprovalRecord
  215. for _, tmpApprovalRecord := range approvalRecordList {
  216. if tmpApprovalRecord.NodeType == "check" && tmpApprovalRecord.ApproveUserId == this.AdminWx.AdminId {
  217. approvalRecord = tmpApprovalRecord
  218. }
  219. }
  220. if approvalRecord == nil {
  221. this.FailWithMessage("当前账号没有审批权限", "当前账号没有审批权限")
  222. }
  223. err = sealService.Reject(approvalRecord, this.AdminWx, req.Remark)
  224. if err != nil {
  225. this.FailWithMessage("驳回审批失败!", "驳回审批失败,Err:"+err.Error())
  226. return
  227. }
  228. this.OkWithMessage("驳回成功")
  229. }
  230. // @Title 处理审批单
  231. // @Description 处理审批单
  232. // @Param request body contract.ApprovedReq true "type json string"
  233. // @Success Ret=200 申请成功
  234. // @router /approved [post]
  235. func (this *SealApprovalCommon) Approved() {
  236. var req contractReq.ApprovedReq
  237. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  238. if err != nil {
  239. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  240. return
  241. }
  242. //审批单id编号
  243. contractApprovalId := req.ApprovalId
  244. if contractApprovalId <= 0 {
  245. this.FailWithMessage("请传入审批单编号!", "请传入审批单编号!")
  246. return
  247. }
  248. //审批单详情
  249. approvalInfo, err := contract_approval.GetContractApprovalById(contractApprovalId)
  250. if err != nil {
  251. this.FailWithMessage("获取审批单失败!", "获取审批单失败,Err:"+err.Error())
  252. return
  253. }
  254. if approvalInfo.Status != "待审批" {
  255. this.FailWithMessage("当前审批单状态异常,不允许审批", "当前审批单状态异常,不允许审批,审批单状态:"+approvalInfo.Status)
  256. }
  257. //审批流
  258. approvalRecordList, err := contract_approval_record.GetContractApprovalRecordListByContractApprovalIdAndNodeId(contractApprovalId, approvalInfo.CurrNodeId)
  259. if err != nil {
  260. this.FailWithMessage("获取审批失败!", "获取审批失败,Err:"+err.Error())
  261. return
  262. }
  263. var approvalRecord *contract_approval_record.ContractApprovalRecord
  264. for _, tmpApprovalRecord := range approvalRecordList {
  265. if tmpApprovalRecord.NodeType == "check" && tmpApprovalRecord.ApproveUserId == this.AdminWx.AdminId {
  266. approvalRecord = tmpApprovalRecord
  267. }
  268. }
  269. if approvalRecord == nil {
  270. this.FailWithMessage("当前账号没有审批权限", "当前账号没有审批权限")
  271. }
  272. err = sealService.Approved(approvalRecord, this.AdminWx, req.Remark)
  273. if err != nil {
  274. this.FailWithMessage("审核失败!", "审核失败,Err:"+err.Error())
  275. return
  276. }
  277. this.OkWithMessage("审核通过")
  278. }