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/company" "hongze/hongze_mobile_admin/models/tables/seal" contractService "hongze/hongze_mobile_admin/services/contract" sealService "hongze/hongze_mobile_admin/services/seal" "hongze/hongze_mobile_admin/utils" "path" "strconv" "strings" ) //SealCommon //用印模块 type SealCommon struct { BaseAuth } //Add // @Title 新增用印 // @Description 新增用印接口 // @Param request body seal.AddReq true "type json string" // @Success Ret=200 新增用印成功 // @router /add [post] func (c *SealCommon) Add() { var req sealReq.AddReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) if err != nil { c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error()) return } // 参数校验 if req.Use == "" { c.FailWithMessage("用印用途不能为空", "用印用途不能为空") return } if req.CompanyName == "" { c.FailWithMessage("客户名称不能为空", "客户名称不能为空") return } if req.CreditCode == "" { c.FailWithMessage("社会统一信用代码不能为空", "社会统一信用代码不能为空") return } if req.ServiceType == "" { c.FailWithMessage("合同类型不能为空", "合同类型不能为空") return } if req.SealType == "" { c.FailWithMessage("印章类型不能为空", "印章类型不能为空") return } if len(req.FileUrls) == 0 { c.FailWithMessage("合同附件不能为空", "合同附件不能为空") return } if req.AffiliatedCompany == "" { c.FailWithMessage("归属公司不能为空", "归属公司不能为空") } sealInfo, err := sealService.AddSeal(c.AdminWx.AdminId, req.ContractId, req.FileNum, c.AdminWx.RealName, req.Use, req.UseCompanyName, req.CompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls, req.AffiliatedCompany) if err != nil { c.FailWithMessage("用印添加失败", err.Error()) return } err = sealService.Apply(sealInfo) if err != nil { c.FailWithMessage("发起用印审批失败", "发起用印审批失败,Err:"+err.Error()) return } c.OkDetailed(sealResp.AddSealResp{ SealId: sealInfo.SealId, }, "发起用印审批成功") } //Edit // @Title 编辑用印 // @Description 编辑用印接口 // @Param request body seal.EditReq true "type json string" // @Success 200 {object} seal.AddSealResp // @router /edit [post] func (c *SealCommon) Edit() { var req sealReq.EditReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) if err != nil { c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error()) return } // 参数校验 if req.SealId <= 0 { c.FailWithMessage("用印编号不能为空", "用印编号不能为空") return } if req.Use == "" { c.FailWithMessage("用印用途不能为空", "用印用途不能为空") return } if req.CompanyName == "" { c.FailWithMessage("客户名称不能为空", "客户名称不能为空") return } if req.CreditCode == "" { c.FailWithMessage("社会统一信用代码不能为空", "社会统一信用代码不能为空") return } if req.ServiceType == "" { c.FailWithMessage("合同类型不能为空", "合同类型不能为空") return } if req.SealType == "" { c.FailWithMessage("印章类型不能为空", "印章类型不能为空") return } if len(req.FileUrls) == 0 { c.FailWithMessage("合同附件不能为空", "合同附件不能为空") return } if req.AffiliatedCompany == "" { c.FailWithMessage("归属公司不能为空", "归属公司不能为空") } sealInfo, err := sealService.Edit(req.SealId, c.AdminWx.AdminId, req.ContractId, req.FileNum, req.Use, req.CompanyName, req.UseCompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls, c.AdminWx.RealName, req.AffiliatedCompany) if err != nil { c.FailWithMessage("修改合同失败!", "修改合同失败,Err:"+err.Error()) return } tmpErr := sealService.Apply(sealInfo) if tmpErr != nil { c.FailWithMessage("发起重申失败!", "发起重申失败,Err:"+tmpErr.Error()) return } c.OkDetailed(sealResp.AddSealResp{ SealId: sealInfo.SealId, }, "发起重申成功") } //CheckEdit // @Title 审批者编辑用印 // @Description 审批者编辑用印接口 // @Param request body seal.CheckEditReq true "type json string" // @Success 200 {object} seal.AddSealResp // @router /check_edit [post] func (c *SealCommon) CheckEdit() { var req sealReq.CheckEditReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) if err != nil { c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error()) return } // 参数校验 sealId := req.SealId if sealId <= 0 { c.FailWithMessage("用印编号不能为空", "用印编号不能为空") return } if req.Use == "" { c.FailWithMessage("用印用途不能为空", "用印用途不能为空") return } if req.SealType == "" { c.FailWithMessage("印章类型不能为空", "印章类型不能为空") return } if len(req.FileUrls) == 0 { c.FailWithMessage("合同附件不能为空", "合同附件不能为空") return } if req.AffiliatedCompany == "" { c.FailWithMessage("归属公司不能为空", "归属公司不能为空") } //数据校验(校验是否具有审批权限) sealInfo, approvalInfo, approvalRecord, err := sealService.CheckApproveAuth(sealId, c.AdminWx) //合规修改 err = sealService.CheckEdit(sealInfo, approvalInfo, approvalRecord, req.FileNum, req.FileUrls, req.Use, req.SealType, req.Remark, req.AffiliatedCompany, c.AdminWx) if err != nil { c.FailWithMessage("修改合同失败!", "修改合同失败,Err:"+err.Error()) return } c.OkDetailed(sealResp.AddSealResp{ SealId: sealInfo.SealId, }, "修改合同成功") } // List // @Title 用印列表 // @Description 用印列表接口 // @Param Status query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废','已签回'" // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益" // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00" // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59" // @Param AdminId query string false "选择的用户id" // @Param Keyword query string false "搜索关键字" // @Param KeywordEq query string false "搜索关键字(全匹配搜索)" // @Success 200 {object} contract.ContractListResp // @router /list [get] func (c *SealCommon) List() { //合同类型、产品类型、合同状态、更新时间、所选销售 //关键字:合同编号、客户名称,社会信用码 status := c.GetString("Status") productId, _ := c.GetInt("ProductId") modifyStartTime := c.GetString("ModifyStartTime") modifyEndTime := c.GetString("ModifyEndTime") adminIds := c.GetString("AdminId") keyword := c.GetString("Keyword") keywordEq := c.GetString("KeywordEq") affiliatedCompany := c.GetString("AffiliatedCompany") condition := "" pars := make([]interface{}, 0) //合同类型、、更新时间、所选销售 //关键字:合同编号、客户名称,社会信用码 //合同状态 if status != "" { condition += ` AND status = ? ` pars = append(pars, status) } //产品类型 if productId > 0 { condition += ` AND product_id = ? ` pars = append(pars, productId) } //所选销售 if adminIds != "" { condition += ` AND user_id IN (` + adminIds + `) ` } else { condition += ` AND user_id =?` pars = append(pars, c.AdminWx.AdminId) } //更新开始时间 if modifyStartTime != "" { condition += ` AND modify_time >= ? ` pars = append(pars, modifyStartTime) } //更新结束时间 if modifyEndTime != "" { condition += ` AND modify_time <= ? ` pars = append(pars, modifyEndTime) } //关键字 if keyword != "" { condition += ` AND (code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR 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 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) total, err := seal.GetListCount(condition, pars) if err != nil { c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error()) return } list, err := seal.GetList(condition, pars, startSize, pageSize) if err != nil { c.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error()) return } page := paging.GetPaging(currentIndex, pageSize, total) c.OkDetailed(sealResp.RespSealList{ List: list, Paging: page, }, "获取成功") } //Detail // @Title 获取用印详情 // @Description 获取用印详情接口 // @Param SealId query int true "用印id" // @Success 200 {object} seal.SealDetailResp // @router /detail [get] func (c *SealCommon) Detail() { //合同类型、产品类型、合同状态、更新时间、所选销售 //关键字:合同编号、客户名称,社会信用码 sealId, _ := c.GetInt("SealId") //用印id if sealId <= 0 { c.FailWithMessage("用印id必传!", "用印id必传!") return } 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, "获取成功") } //Invalid // @Title 作废合同 // @Description 作废合同接口 // @Param request body seal.InvalidReq true "type json string" // @Success Ret=200 作废成功 // @router /invalid [post] func (c *SealCommon) Invalid() { var req sealReq.InvalidReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) if err != nil { c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error()) return } //用印id if req.SealId <= 0 { c.FailWithMessage("用印id必传!", "用印id必传!") return } err = sealService.Invalid(req.SealId, c.AdminWx, req.IsInvalidContract) if err != nil { c.FailWithMessage("作废用印失败!", "作废用印失败,Err:"+err.Error()) return } c.OkWithMessage("作废成功") return } // UploadCheckBackFile // @Title 上传签回附件 // @Description 上传签回附件接口 // @Param request body seal.UploadCheckBackFileReq true "type json string" // @Success Ret=200 上传成功 // @router /upload_check_back_file [post] func (c *SealCommon) UploadCheckBackFile() { //var req sealReq.UploadCheckBackFileReq //err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) //if err != nil { // c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error()) // return //} ////用印编号 //if req.SealId <= 0 { // c.FailWithMessage("请传入用印编号!", "请传入用印编号") // return //} // //if req.FileUrl == "" { // c.FailWithMessage("请先上传附件!", "请先上传附件") // return //} sealIdStr := c.Ctx.Request.Form.Get("SealId") if sealIdStr == "" { c.FailWithMessage("用印ID必传!", "用印ID必传") return } sealId, err := strconv.Atoi(sealIdStr) if err != nil { c.FailWithMessage("用印ID异常!", "用印ID必传") return } //合同编号 if sealId <= 0 { c.FailWithMessage("请传入用印编号", "请传入用印编号") return } fileMulti, h, err := c.GetFile("file") if err != nil { c.FailWithMessage("获取资源信息失败", "获取资源信息失败,Err:"+err.Error()) return } ext := path.Ext(h.Filename) //sealInfo, err := sealService.UploadCheckBackFile(req.SealId, req.FileUrl, c.AdminWx) sealInfo, err := sealService.UploadCheckBackFileByFile(sealId, ext, fileMulti, c.AdminWx) if err != nil { c.FailWithMessage("更新签回附件失败!", "更新签回附件失败,Err:"+err.Error()) return } //如果是系统合同,那么需要去更新系统的签回附件 if sealInfo.ContractId > 0 { _ = contractService.UploadCheckBackFile(sealInfo.ContractId, sealInfo.CheckBackFileUrl, c.AdminWx) } c.OkWithMessage("上传成功") } //CompanyList // @Title 根据客户名称获取已存在系统中客户名称列表 // @Description 获取合同详情接口 // @Param Keyword query string true "关键字:客户名称、组织社会信用码" // @Success 200 {object} []string // @router /company_list [get] func (c *SealCommon) CompanyList() { sysUser := c.AdminWx keyword := c.GetString("Keyword") //合同id if keyword == "" { c.FailWithMessage("搜索关键字必传!", "搜索关键字必传!") return } companyNameList := make([]string, 0) childCondition := "" condition := "" childPars := make([]interface{}, 0) pars := make([]interface{}, 0) //归属 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) condition += ` AND (c.company_name like "%` + keyword + `%" or c.credit_code like "%` + keyword + `%")` list, err := seal.GetCompanyNameListV2(childCondition, condition, childPars, pars) if err != nil { c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error()) return } for _, v := range list { companyNameList = append(companyNameList, v.CompanyName) } c.OkDetailed(companyNameList, "获取成功") } // CompanyNameList // @Title 根据客户名称关键词获取系统中的客户名称列表 // @Description 获取客户名称列表 // @Param Keyword query string true "客户名称关键词" // @Param PageSize query int true "每页数据量" // @Param CurrentIndex query int true "页码" // @Success 200 {object} []company.CompanyNameList // @router /company_name_list [get] func (c *SealCommon) CompanyNameList() { keyword := c.GetString("Keyword") pageSize, _ := c.GetInt("PageSize") currentIndex, _ := c.GetInt("CurrentIndex") if keyword == "" { c.FailWithMessage("关键词不能为空", "关键词不能为空") return } var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) keyword = "%" + keyword + "%" condition := " AND company_name LIKE ? " pars := make([]interface{}, 0) pars = append(pars, keyword) list, err := company.GetCompanyNameList(condition, pars, startSize, pageSize) if err != nil { c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error()) return } c.OkDetailed(list, "获取成功") } // 关联公司列表 // @Title 关联公司列表 // @Description 关联公司列表 // @Success 200 {object} response.SealApprovalListResp // @router /getAffiliatedCompany [get] func (c *SealCommon) AffiliatedCompanyList() { crmConfig, err := company.GetConfigDetailByCode("affiliated_company") if err != nil { c.FailWithMessage( "获取配置失败!", "获取配置失败,Err:"+err.Error()) return } list := strings.Split(crmConfig.ConfigValue, ",") c.OkDetailed(list, "获取成功") }