123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- package controllers
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- sealReq "hongze/hongze_mobile_admin/models/request/seal"
- sealResp "hongze/hongze_mobile_admin/models/response/seal"
- "hongze/hongze_mobile_admin/models/tables/contract_approval"
- "hongze/hongze_mobile_admin/models/tables/contract_approval_record"
- "hongze/hongze_mobile_admin/models/tables/seal"
- sealService "hongze/hongze_mobile_admin/services/seal"
- "hongze/hongze_mobile_admin/utils"
- "strconv"
- "strings"
- )
- //SealApprovalCommon 用印审批模块
- type SealApprovalCommon struct {
- BaseAuth
- }
- // List
- // @Title 审批单列表
- // @Description 审批单列表接口
- // @Param Use query string false "用途,枚举值:销售合同, 渠道合同, 付款通知函, 招投标, 战略合作协议"
- // @Param ServiceType query string false "业务类型,枚举值:"新签合同, 续约合同, 补充协议"
- // @Param SealType query string false "公章类型,枚举值:合同章, 公章, 法人章"
- // @Param Status query string false "合同状态,枚举值:'待审批','已审批','已驳回','已撤回','已签回'"
- // @Param UserId query string false "选择的申请人id"
- // @Param Keyword query string false "搜索关键字"
- // @Param KeywordEq query string false "搜索关键字(全等)"
- // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
- // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
- // @Success 200 {object} seal.SealApprovalListResp
- // @router /list [get]
- func (c *SealApprovalCommon) List() {
- sysUser := c.AdminWx
- //合同类型、产品类型、合同状态、更新时间、所选销售
- //关键字:合同编号、客户名称,社会信用码
- serviceType := c.GetString("ServiceType")
- use := c.GetString("Use")
- sealType := c.GetString("SealType")
- status := c.GetString("Status")
- productId, _ := c.GetInt("ProductId")
- sellerIds := c.GetString("SellerId")
- keyword := c.GetString("Keyword")
- keywordEq := c.GetString("KeywordEq")
- modifyStartTime := c.GetString("ModifyStartTime")
- modifyEndTime := c.GetString("ModifyEndTime")
- affiliatedCompany := c.GetString("AffiliatedCompany")
- childCondition := ""
- condition := ""
- childPars := make([]interface{}, 0)
- pars := make([]interface{}, 0)
- ////如果不是超管或者合规,那么只能查看自己的合同
- //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //权益管理员
- // condition += ` AND c.product_id = ? `
- // pars = append(pars, 2)
- //} else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN { //ficc管理员
- // condition += ` AND c.product_id = ? `
- // pars = append(pars, 1)
- //} else {
- // if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- // condition += ` AND c.seller_id = ? `
- // pars = append(pars, sysUser.AdminId)
- // }
- //}
- //join表字段
- joinCondition := " and a.curr_node_id=d.node_id"
- //归属
- if status == "待审批" {
- condition += ` AND ( (((c.user_id = ? and a.start_node_id = a.curr_node_id) OR (d.approve_user_id = ? and a.curr_node_id=d.node_id)) and d.status="待审批") or (d.approve_user_id = ? and a.curr_node_id > d.node_id and d.node_type="cc") )`
- //condition += ` AND (c.user_id = ? OR d.approve_user_id = ?) and (d.approve_user_id is null or d.approve_user_id = c.user_id)`
- joinCondition = ``
- pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
- } else if status == "处理中" {
- condition += ` AND ((c.user_id = ? and a.start_node_id != a.curr_node_id) OR (d.approve_user_id = ? and a.curr_node_id > d.node_id and d.node_type!="cc")) and c.status="待审批" `
- joinCondition = " and a.curr_node_id!=d.node_id"
- pars = append(pars, sysUser.AdminId, sysUser.AdminId)
- } else if status == "其它" {
- condition += ` AND ( (c.user_id = ? and c.status in ("已撤回","已作废") ) or (d.approve_user_id = ? and d.node_id <= a.curr_node_id and c.status = "已作废" ))`
- pars = append(pars, sysUser.AdminId, sysUser.AdminId)
- } else {
- condition += ` AND (c.user_id = ? or (d.approve_user_id = ? and d.node_id <= a.curr_node_id))`
- pars = append(pars, sysUser.AdminId, sysUser.AdminId)
- }
- //合同类型、、更新时间、所选销售
- //关键字:合同编号、客户名称,社会信用码
- if use != "" {
- condition += ` AND c.use = ? `
- pars = append(pars, use)
- }
- if serviceType != "" {
- condition += ` AND c.service_type = ? `
- pars = append(pars, serviceType)
- }
- if sealType != "" {
- condition += ` AND c.seal_type = ? `
- pars = append(pars, sealType)
- }
- //审批状态
- if status != "" {
- if status == "已审批" {
- condition += ` AND c.status in ("已审批","已驳回") `
- } else if status != "其它" { //其它状态额外处理,这边不处理
- condition += ` AND c.status = ? `
- if status == "处理中" {
- pars = append(pars, "待审批")
- } else {
- pars = append(pars, status)
- }
- //if status == "待审批" {
- // condition += ` AND a.status = ? `
- // pars = append(pars, status)
- //}
- }
- } else {
- //childCondition += ` AND status != "已撤回" `
- condition += ` AND c.status not in ("已撤回","待提交") `
- }
- //产品类型
- if productId > 0 {
- condition += ` AND c.product_id = ? `
- pars = append(pars, productId)
- }
- //所选销售
- if sellerIds != "" {
- condition += ` AND c.user_id IN (` + sellerIds + `) `
- }
- //更新开始时间
- //更新开始时间
- if modifyStartTime != "" {
- condition += ` AND a.modify_time >= ? `
- pars = append(pars, modifyStartTime)
- }
- //更新结束时间
- if modifyEndTime != "" {
- condition += ` AND a.modify_time <= ? `
- pars = append(pars, modifyEndTime)
- }
- //关键字
- if keyword != "" {
- condition += ` AND (c.code LIKE '%` + keyword + `%' OR c.use_company_name LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
- }
- //关键字(全等)
- if keywordEq != "" {
- condition += ` AND (c.use_company_name =? OR c.company_name =?) `
- pars = append(pars, keywordEq, keywordEq)
- }
- // 归属公司
- if affiliatedCompany != "" {
- condition += ` AND c.affiliated_company =? `
- pars = append(pars, affiliatedCompany)
- }
- pageSize, _ := c.GetInt("PageSize")
- currentIndex, _ := c.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var total int
- var list []*contract_approval.SealApprovalList
- if status != "待审批" && status != "处理中" {
- tmpTotal, err := contract_approval.GetSealApprovalListCountV2(childCondition, condition, childPars, pars)
- if err != nil {
- c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
- return
- }
- orderBy := ` modify_time desc `
- switch status {
- case "已撤回":
- orderBy = ` c.modify_time desc `
- case "已作废":
- orderBy = ` c.invalid_time desc `
- }
- tmpList, err := contract_approval.GetSealApprovalListV2(childCondition, condition, orderBy, childPars, pars, startSize, pageSize)
- if err != nil {
- c.FailWithMessage("获取审批列表失败!", "获取审批列表失败,Err:"+err.Error())
- return
- }
- total = tmpTotal
- list = tmpList
- } else {
- tmpTotal, err := contract_approval.GetSealApprovalListCount(childCondition, condition, joinCondition, childPars, pars)
- if err != nil {
- c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
- return
- }
- tmpList, err := contract_approval.GetSealApprovalList(childCondition, condition, joinCondition, childPars, pars, startSize, pageSize)
- if err != nil {
- c.FailWithMessage("获取审批列表失败!", "获取审批列表失败,Err:"+err.Error())
- return
- }
- total = tmpTotal
- list = tmpList
- }
- if len(list) > 0 {
- contractApprovalIdSlice := make([]string, 0)
- for i := 0; i < len(list); i++ {
- contractApprovalIdSlice = append(contractApprovalIdSlice, strconv.Itoa(list[i].ContractApprovalId))
- }
- contractApprovalIdStr := strings.Join(contractApprovalIdSlice, ",")
- //获取当前审批流列表数据
- contractApprovalRecordList, err := contract_approval_record.GetContractApprovalRecordList(contractApprovalIdStr, sysUser.AdminId)
- if err != nil {
- c.FailWithMessage("获取审批列表失败!", "获取审批列表失败,Err:"+err.Error())
- return
- }
- contractApprovalRecordMap := make(map[int]*contract_approval_record.ContractApprovalRecord)
- for i := 0; i < len(contractApprovalRecordList); i++ {
- contractApprovalRecordMap[contractApprovalRecordList[i].ContractApprovalId] = contractApprovalRecordList[i]
- }
- //获取自己的审批流列表数据
- selfContractApprovalRecordList, err := contract_approval_record.GetSelfContractApprovalRecordList(contractApprovalIdStr, sysUser.AdminId)
- if err != nil {
- c.FailWithMessage("获取审批列表失败!", "获取审批列表失败,Err:"+err.Error())
- return
- }
- selfContractApprovalRecordMap := make(map[int]*contract_approval_record.ContractApprovalRecord)
- for i := 0; i < len(selfContractApprovalRecordList); i++ {
- selfContractApprovalRecordMap[selfContractApprovalRecordList[i].ContractApprovalId] = selfContractApprovalRecordList[i]
- }
- for i := 0; i < len(list); i++ {
- item := list[i]
- list[i].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
- list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
- if item.ApproveStatus == "已审批" || item.ApproveStatus == "已驳回" {
- list[i].ApproveTime = item.ModifyTime
- list[i].ApproveTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
- }
- //list[i].ContractInfo = contractDetail
- //如果当前状态是待审批的话,那么校验自己的审批流数据,然后去返回对应的状态
- if item.Status == "待审批" {
- //如果是自己发起的审批单,同时已经经过了一轮审批,那么标记为处理中
- if item.ApplyUserId == c.AdminWx.AdminId && item.CurrNodeId > item.StartNodeId {
- list[i].Status = "处理中"
- } else {
- if contractApprovalRecord, has := selfContractApprovalRecordMap[item.ContractApprovalId]; has {
- if contractApprovalRecord.NodeId < item.CurrNodeId && contractApprovalRecord.NodeType != "cc" {
- list[i].Status = "处理中"
- }
- }
- }
- }
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- c.OkDetailed(sealResp.SealApprovalListResp{
- List: list,
- Paging: page,
- }, "获取成功")
- }
- // Detail
- // @Title 审批单详情
- // @Description 审批单详情接口
- // @Param SealId query int false "用印id"
- // @Param ContractApprovalId query int false "审批单id"
- // @Param ContractApprovalRecordId query int false "审批流程单id"
- // @Success 200 {object} seal.SealDetailResp
- // @router /detail [get]
- func (c *SealApprovalCommon) Detail() {
- //审批流程单id
- contractApprovalRecordId, _ := c.GetInt("ContractApprovalRecordId")
- if contractApprovalRecordId > 0 {
- c.detailByApprovalRecordId(contractApprovalRecordId)
- return
- }
- //用印id
- sealId, _ := c.GetInt("SealId")
- if sealId <= 0 {
- //审批单id
- contractApprovalId, _ := c.GetInt("ContractApprovalId")
- if contractApprovalId <= 0 {
- c.FailWithMessage("获取审批单失败!审批单id未传", "获取审批单失败!审批单id未传")
- return
- }
- //审批单详情
- contractApprovalInfo, err := contract_approval.GetContractApprovalById(contractApprovalId)
- if err != nil {
- c.FailWithMessage("获取审批单失败!", "获取审批单失败,Err:"+err.Error())
- return
- }
- sealId = contractApprovalInfo.ContractId
- }
- //用印详情
- sealInfo, flowNodeListResp, opButton, err := sealService.GetSealDetailBySealId(sealId, c.AdminWx)
- if err != nil {
- c.FailWithMessage("获取详情失败", "获取详情失败,Err:"+err.Error())
- return
- }
- resp := sealResp.SealDetailResp{
- SealDetail: sealInfo,
- FlowNodeList: flowNodeListResp,
- OpButton: opButton,
- }
- c.OkDetailed(resp, "获取成功")
- }
- func (c *SealApprovalCommon) detailByApprovalRecordId(approvalRecordId int) {
- approvalRecordInfo, err := contract_approval_record.GetContractApprovalRecordById(approvalRecordId)
- if err != nil {
- c.FailWithMessage("获取审批流程单失败", "获取审批流程单失败,Err:"+err.Error())
- return
- }
- //审批单详情
- contractApprovalInfo, err := contract_approval.GetContractApprovalById(approvalRecordInfo.ContractApprovalId)
- if err != nil {
- c.FailWithMessage("获取审批单失败", "获取审批单失败,Err:"+err.Error())
- return
- }
- //用印详情
- sealInfo, flowNodeListResp, opButton, err := sealService.GetSealDetailBySealId(contractApprovalInfo.ContractId, c.AdminWx)
- if err != nil {
- c.FailWithMessage("获取详情失败", "获取详情失败,Err:"+err.Error())
- return
- }
- resp := sealResp.SealDetailResp{
- SealDetail: sealInfo,
- FlowNodeList: flowNodeListResp,
- OpButton: opButton,
- }
- c.OkDetailed(resp, "获取成功")
- return
- }
- // Reject
- // @Title 驳回审批
- // @Description 驳回审批接口
- // @Param request body seal.RejectReq true "type json string"
- // @Success Ret=200 驳回成功
- // @router /reject [post]
- func (c *SealApprovalCommon) Reject() {
- var req sealReq.RejectReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- //用印id编号
- sealId := req.SealId
- if sealId <= 0 {
- c.FailWithMessage("请传入用印单编号!", "请传入用印单编号!")
- return
- }
- remark := strings.Trim(req.Remark, " ")
- if remark == "" {
- c.FailWithMessage("请输入驳回理由!", "请输入驳回理由!")
- return
- }
- //数据校验
- sealInfo, approvalInfo, approvalRecord, err := sealService.CheckApproveAuth(sealId, c.AdminWx)
- if err != nil {
- c.FailWithMessage("驳回审批失败!", "驳回审批失败,Err:"+err.Error())
- return
- }
- err = sealService.Reject(sealInfo, approvalInfo, approvalRecord, c.AdminWx, remark)
- if err != nil {
- c.FailWithMessage("驳回审批失败!", "驳回审批失败,Err:"+err.Error())
- return
- }
- c.OkWithMessage("驳回成功")
- }
- // Approved
- // @Title 处理审批单
- // @Description 处理审批单
- // @Param request body seal.ApprovedReq true "type json string"
- // @Success Ret=200 申请成功
- // @router /approved [post]
- func (c *SealApprovalCommon) Approved() {
- var req sealReq.ApprovedReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- //用印编号id编号
- sealId := req.SealId
- if sealId <= 0 {
- c.FailWithMessage("请传入用印单编号!", "请传入用印单编号!")
- return
- }
- //数据校验
- sealInfo, approvalInfo, approvalRecord, err := sealService.CheckApproveAuth(sealId, c.AdminWx)
- if err != nil {
- c.FailWithMessage("驳回审批失败!", "驳回审批失败,Err:"+err.Error())
- return
- }
- err = sealService.Approved(sealInfo, approvalInfo, approvalRecord, c.AdminWx, req.Remark)
- if err != nil {
- c.FailWithMessage("审核失败!", "审核失败,Err:"+err.Error())
- return
- }
- c.OkWithMessage("审核通过")
- }
- // CancelApply
- // @Title 撤回审批申请
- // @Description 撤回审批申请接口
- // @Param SealId query int true "用印id编号"
- // @Success Ret=200 撤回申请成功
- // @router /cancelApply [get]
- func (c *SealApprovalCommon) CancelApply() {
- //用印id编号
- sealId, err := c.GetInt("SealId")
- if err != nil {
- c.FailWithMessage("获取审批流编号失败", "获取审批流编号失败,err:"+err.Error())
- return
- }
- //获取用印信息
- sealInfo, err := seal.GetSealInfoById(sealId)
- if err != nil {
- c.FailWithMessage("获取审批流信息失败", "获取审批流信息失败,err:"+err.Error())
- return
- }
- err = sealService.CancelApply(sealInfo, c.AdminWx.AdminId, c.AdminWx.RealName)
- if err != nil {
- c.FailWithMessage("撤回申请失败!", "撤回申请失败,Err:"+err.Error())
- return
- }
- c.OkWithMessage("撤回申请成功")
- }
|