contract_approval.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. package controllers
  2. import (
  3. "encoding/json"
  4. contractReq "hongze/hongze_mobile_admin/models/request/contract"
  5. "hongze/hongze_mobile_admin/models/response/contract"
  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 ContractApprovalCommon 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 *ContractApprovalCommon) 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.seller_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.seller_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.GetContractApprovalListCount(condition, pars)
  114. total, err := contract_approval.GetContractApprovalListCount(childCondition, condition, childPars, pars)
  115. if err != nil {
  116. this.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  117. return
  118. }
  119. list, err := contract_approval.GetContractApprovalList(childCondition, condition, childPars, pars, startSize, pageSize)
  120. if err != nil {
  121. this.FailWithMessage("获取审批列表失败!", "获取审批列表失败,Err:"+err.Error())
  122. return
  123. }
  124. if len(list) > 0 {
  125. contractApprovalIdSlice := make([]string, 0)
  126. for i := 0; i < len(list); i++ {
  127. contractApprovalIdSlice = append(contractApprovalIdSlice, strconv.Itoa(list[i].ContractApprovalId))
  128. }
  129. contractApprovalIdStr := strings.Join(contractApprovalIdSlice, ",")
  130. //获取审批流列表数据
  131. contractApprovalRecordList, err := contract_approval_record.GetContractApprovalRecordList(contractApprovalIdStr, sysUser.AdminId)
  132. if err != nil {
  133. this.FailWithMessage("获取审批列表失败!", "获取审批列表失败,Err:"+err.Error())
  134. return
  135. }
  136. contractApprovalRecordMap := make(map[int]*contract_approval_record.ContractApprovalRecord)
  137. for i := 0; i < len(contractApprovalRecordList); i++ {
  138. contractApprovalRecordMap[contractApprovalRecordList[i].ContractApprovalId] = contractApprovalRecordList[i]
  139. }
  140. for i := 0; i < len(list); i++ {
  141. item := list[i]
  142. list[i].StartDateStr = item.StartDate.Format(utils.FormatDate)
  143. list[i].EndDateStr = item.EndDate.Format(utils.FormatDate)
  144. list[i].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
  145. list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
  146. //list[i].ContractInfo = contractDetail
  147. //校验最新审批流数据
  148. if contractApprovalRecord, has := contractApprovalRecordMap[item.ContractApprovalId]; has {
  149. //审批流id
  150. list[i].ContractApprovalRecordId = contractApprovalRecord.ContractApprovalRecordId
  151. //审批时间
  152. list[i].ApproveTime = contractApprovalRecord.ApproveTime
  153. list[i].ApproveTimeStr = contractApprovalRecord.ApproveTime.Format(utils.FormatDateTime)
  154. //判断是否有操作权限
  155. list[i].Status = contractApprovalRecord.Status
  156. //判断是否处于待审批状态
  157. if contractApprovalRecord.Status == "待审批" {
  158. //如果不是审批者,那么不能审批操作
  159. if contractApprovalRecord.NodeType != "check" {
  160. continue
  161. }
  162. //如果没有指定审批人的话
  163. if contractApprovalRecord.ApproveUserId <= 0 {
  164. //判断是否与审批角色一致,如果一致,那么允许操作审批
  165. if contractApprovalRecord.ApproveRoleTypeCode == sysUser.RoleTypeCode {
  166. list[i].CanApprovalButton = true
  167. }
  168. } else if contractApprovalRecord.ApproveUserId == sysUser.AdminId {
  169. //如果指定审批人就是自己的话,那么操作审批
  170. list[i].CanApprovalButton = true
  171. }
  172. }
  173. }
  174. //合同状态(突然说要改成展示合同状态,那就根据业务需求,改成返回:合同状态咯)
  175. list[i].Status = item.ContractStatus
  176. }
  177. }
  178. page := paging.GetPaging(currentIndex, pageSize, total)
  179. this.OkDetailed(contract.ContractApprovalListResp{
  180. List: list,
  181. Paging: page,
  182. }, "获取成功")
  183. }
  184. // @Title 驳回审批
  185. // @Description 驳回审批接口
  186. // @Param request body contract.RejectReq true "type json string"
  187. // @Success Ret=200 驳回成功
  188. // @router /reject [post]
  189. func (this *ContractApprovalCommon) Reject() {
  190. var req contractReq.RejectReq
  191. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  192. if err != nil {
  193. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  194. return
  195. }
  196. //审批流id编号
  197. contractApprovalRecordId := req.ContractApprovalRecordId
  198. if contractApprovalRecordId <= 0 {
  199. this.FailWithMessage("请传入审批流编号!", "请传入审批流编号")
  200. return
  201. }
  202. //获取审批流信息
  203. contractApprovalRecord, err := contract_approval_record.GetContractApprovalRecordById(contractApprovalRecordId)
  204. if err != nil {
  205. this.FailWithMessage("获取审批流信息失败!", "获取审批流信息失败,Err:"+err.Error())
  206. return
  207. }
  208. err = contractService.Reject(contractApprovalRecord, this.AdminWx, req.Remark)
  209. if err != nil {
  210. this.FailWithMessage("驳回审批失败!", "驳回审批失败,Err:"+err.Error())
  211. return
  212. }
  213. this.OkWithMessage("驳回成功")
  214. }
  215. // @Title 处理审批单
  216. // @Description 处理审批单
  217. // @Param request body request.ApprovedReq true "type json string"
  218. // @Success Ret=200 申请成功
  219. // @router /approved [post]
  220. func (this *ContractApprovalCommon) Approved() {
  221. var req contractReq.ApprovedReq
  222. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  223. if err != nil {
  224. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  225. return
  226. }
  227. //审批流id编号
  228. contractApprovalRecordId := req.ContractApprovalRecordId
  229. if contractApprovalRecordId <= 0 {
  230. this.FailWithMessage("请传入审批流编号!", "请传入审批流编号")
  231. return
  232. }
  233. //获取审批流信息
  234. contractApprovalRecord, err := contract_approval_record.GetContractApprovalRecordById(contractApprovalRecordId)
  235. if err != nil {
  236. this.FailWithMessage("获取审批流信息失败!", "获取审批流信息失败,Err:"+err.Error())
  237. return
  238. }
  239. err = contractService.Approved(contractApprovalRecord, this.AdminWx, req.Remark)
  240. if err != nil {
  241. this.FailWithMessage("审核失败!", "审核失败,Err:"+err.Error())
  242. return
  243. }
  244. this.OkWithMessage("审核通过")
  245. }