seal_approval.go 12 KB

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