seal_approval.go 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. package seal
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "github.com/tealeg/xlsx"
  8. "hongze/hz_crm_api/controllers"
  9. "hongze/hz_crm_api/models"
  10. "hongze/hz_crm_api/models/company"
  11. "hongze/hz_crm_api/models/contract"
  12. sealModels "hongze/hz_crm_api/models/seal"
  13. "hongze/hz_crm_api/models/seal/request"
  14. "hongze/hz_crm_api/models/seal/response"
  15. "hongze/hz_crm_api/services/seal"
  16. "hongze/hz_crm_api/utils"
  17. "os"
  18. "path/filepath"
  19. "strconv"
  20. "strings"
  21. "time"
  22. )
  23. // 用印审批管理
  24. type SealApprovalController struct {
  25. controllers.BaseAuthController
  26. }
  27. // 用印审批列表-分页
  28. // @Title 用印审批列表
  29. // @Description 用印审批列表
  30. // @Param PageSize query int true "每页数据条数"
  31. // @Param CurrentIndex query int true "当前页页码,从1开始"
  32. // @Param ContractType query string false "合同类型 新签合同/续签合同/代付合同"
  33. // @Param Status query string false "用印状态 待审批/处理中/已审批/已驳回/已签回/已作废"
  34. // @Param SellerId query string false "所属销售ID,多个逗号拼接"
  35. // @Param StartTime query string false "提交开始时间"
  36. // @Param EndTime query string false "提交结束时间"
  37. // @Param Keyword query string false "搜索关键词(客户名称/社会信用码)"
  38. // @Param IsExport query bool false "是否导出excel,默认是false"
  39. // @Param AffiliatedCompany query string false "归属公司"
  40. // @Success 200 {object} response.SealApprovalListResp
  41. // @router /getApprovalPageList [get]
  42. func (this *SealApprovalController) List() {
  43. br := new(models.BaseResponse).Init()
  44. defer func() {
  45. this.Data["json"] = br
  46. this.ServeJSON()
  47. }()
  48. sysUser := this.SysUser
  49. if sysUser == nil {
  50. br.Msg = "请登录"
  51. br.ErrMsg = "请登录,SysUser is Empty"
  52. br.Ret = 408
  53. return
  54. }
  55. // 分页
  56. pageSize, _ := this.GetInt("PageSize")
  57. currentIndex, _ := this.GetInt("CurrentIndex")
  58. var startSize int
  59. if pageSize <= 0 {
  60. pageSize = utils.PageSize20
  61. }
  62. if currentIndex <= 0 {
  63. currentIndex = 1
  64. }
  65. startSize = paging.StartIndex(currentIndex, pageSize)
  66. isExport, _ := this.GetBool("IsExport", false)
  67. // 筛选条件
  68. condition := ""
  69. joinCondition := " AND a.curr_node_id = d.node_id" // contract_approval和contract_approval_record的join条件
  70. pars := make([]interface{}, 0)
  71. // 数据权限
  72. reqStatus := this.GetString("Status")
  73. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  74. // 超管
  75. condition += ` AND c.status != "已撤回" `
  76. if reqStatus != "" {
  77. if reqStatus == "待审批" {
  78. // 当前审批节点小于等于审批节点且状态为-待审批
  79. condition += ` AND (a.curr_node_id <= a.start_node_id AND c.status = "待审批") `
  80. joinCondition = ``
  81. } else if reqStatus == "处理中" {
  82. // 当前审批节点大于开始审批节点且状态为-待审批
  83. condition += ` AND (a.curr_node_id > a.start_node_id AND c.status = "待审批")`
  84. } else {
  85. condition += ` AND c.status = ?`
  86. pars = append(pars, reqStatus)
  87. }
  88. }
  89. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_COMPLIANCE {
  90. // 合规
  91. if reqStatus != "" {
  92. if reqStatus == "待审批" {
  93. condition += ` AND (d.approve_user_id = ? AND a.curr_node_id <= d.node_id AND d.node_type != "cc") AND c.status="待审批"`
  94. joinCondition = ``
  95. pars = append(pars, sysUser.AdminId)
  96. } else if reqStatus == "处理中" {
  97. condition += ` AND (d.approve_user_id = ? AND a.curr_node_id > d.node_id AND d.node_type != "cc") AND c.status="待审批"`
  98. joinCondition = " AND a.curr_node_id != d.node_id"
  99. pars = append(pars, sysUser.AdminId)
  100. } else if reqStatus == "已撤回" {
  101. condition += ` AND c.status = ? AND c.user_id = ?`
  102. pars = append(pars, reqStatus, sysUser.AdminId)
  103. } else {
  104. condition += ` AND c.status = ?`
  105. pars = append(pars, reqStatus)
  106. }
  107. } else {
  108. condition += ` AND (c.status = "已撤回" AND c.user_id = ? ) OR (c.status != "已撤回") AND (c.status != "待提交")`
  109. pars = append(pars, sysUser.AdminId)
  110. }
  111. } else {
  112. // 销售
  113. condition += ` AND (c.user_id = ? OR (d.approve_user_id = ? AND d.node_id <= a.curr_node_id) OR (d.approve_user_id = ? AND d.node_type = "cc") )`
  114. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
  115. if reqStatus != "" {
  116. switch reqStatus {
  117. case "待审批":
  118. condition += ` AND c.status = "待审批" 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)) ) OR (d.approve_user_id = ? AND a.curr_node_id > d.node_id AND d.node_type="cc") )`
  119. joinCondition = ``
  120. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
  121. case "处理中":
  122. 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="待审批" `
  123. joinCondition = " AND a.curr_node_id != d.node_id"
  124. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  125. case "已撤回":
  126. condition += ` AND (c.status = "已撤回" AND c.user_id = ? ) `
  127. pars = append(pars, sysUser.AdminId)
  128. case "已审批", "已驳回", "已签回", "已作废":
  129. joinCondition = ``
  130. condition += ` AND c.status = ?`
  131. pars = append(pars, reqStatus)
  132. }
  133. } else {
  134. joinCondition = ``
  135. condition += ` AND ((c.status = "已撤回" AND c.user_id = ? ) OR (c.status != "已撤回")) `
  136. pars = append(pars, sysUser.AdminId)
  137. }
  138. }
  139. // 合同类型
  140. reqContractType := this.GetString("ContractType")
  141. if reqContractType != "" {
  142. condition += ` AND c.service_type = ? `
  143. pars = append(pars, reqContractType)
  144. }
  145. // 所属销售-多个
  146. reqSellerId := this.GetString("SellerId")
  147. if reqSellerId != "" {
  148. condition += ` AND c.user_id IN (` + reqSellerId + `)`
  149. }
  150. // 提交时间
  151. reqStartTime := this.GetString("StartTime")
  152. reqEndTime := this.GetString("EndTime")
  153. if reqStartTime != "" && reqEndTime != "" {
  154. reqStartTime += " 00:00:00"
  155. reqEndTime += " 23:59:59"
  156. condition += ` AND c.create_time >= ? AND c.create_time <= ?`
  157. pars = append(pars, reqStartTime, reqEndTime)
  158. }
  159. // 客户名称-社会信用码
  160. reqKeyword := this.GetString("Keyword")
  161. if reqKeyword != "" {
  162. keywords := "%" + reqKeyword + "%"
  163. condition += ` AND (c.company_name LIKE ? OR c.use_company_name LIKE ? OR c.credit_code LIKE ?)`
  164. pars = append(pars, keywords, keywords, keywords)
  165. }
  166. // 归属公司
  167. affiliatedCompany := this.GetString("AffiliatedCompany")
  168. if affiliatedCompany != "" {
  169. condition += ` AND c.affiliated_company = ?`
  170. pars = append(pars, affiliatedCompany)
  171. }
  172. //导出excel
  173. if isExport {
  174. ApprovalListExport(this, condition, joinCondition, pars, br)
  175. return
  176. }
  177. // 列表
  178. listData, listTotal, err := seal.GetSealApprovalPageList(condition, joinCondition, pars, startSize, pageSize, sysUser)
  179. if err != nil {
  180. br.Msg = "审批列表获取失败!"
  181. br.ErrMsg = "审批列表获取失败!" + err.Error()
  182. return
  183. }
  184. page := paging.GetPaging(currentIndex, pageSize, listTotal)
  185. br.Ret = 200
  186. br.Success = true
  187. br.Msg = "获取成功"
  188. br.Data = response.SealApprovalListResp{
  189. Paging: page,
  190. List: listData,
  191. }
  192. }
  193. // ApprovalListExport 审批列表导出
  194. func ApprovalListExport(this *SealApprovalController, condition, joinCondition string, pars []interface{}, br *models.BaseResponse) {
  195. list, err := sealModels.GetSealApprovalList(condition, joinCondition, pars)
  196. if err != nil {
  197. br.Msg = "审批列表获取失败!"
  198. br.ErrMsg = "审批列表获取失败!" + err.Error()
  199. return
  200. }
  201. ////超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  202. //resp := new(cygx.CanDownload)
  203. //adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  204. //if errAdmin != nil {
  205. // br.Msg = "获取失败"
  206. // br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  207. // return
  208. //}
  209. //if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  210. // resp.IsCanDownload = true
  211. //}
  212. if len(list) > 0 {
  213. // 取出所有列表的关联合同id
  214. contractIdSlice := make([]string, 0)
  215. contractApprovalIdSlice := make([]string, 0)
  216. for i := 0; i < len(list); i++ {
  217. contractIdSlice = append(contractIdSlice, strconv.Itoa(list[i].ContractId))
  218. contractApprovalIdSlice = append(contractApprovalIdSlice, strconv.Itoa(list[i].ContractApprovalId))
  219. }
  220. // 获取所有关联的合同列表
  221. selfContractMap := make(map[int]*contract.ContractList)
  222. {
  223. if len(contractIdSlice) > 0 {
  224. contractIdStr := strings.Join(contractIdSlice, ",")
  225. contractList, tempErr := contract.GetContractListByContractIds(contractIdStr)
  226. if tempErr != nil {
  227. err = errors.New(fmt.Sprint("获取合同失败,Err:"+tempErr.Error(), err))
  228. return
  229. }
  230. for i := 0; i < len(contractList); i++ {
  231. selfContractMap[contractList[i].ContractId] = contractList[i]
  232. }
  233. }
  234. }
  235. selfContractApprovalRecordMap := make(map[int][]*contract.ContractApprovalRecord)
  236. {
  237. if len(contractApprovalIdSlice) > 0 {
  238. contractApprovalIdStr := strings.Join(contractApprovalIdSlice, ",")
  239. contractApprovalList, tempErr := contract.GetContractApprovalRecordListByContractApprovalIds(contractApprovalIdStr)
  240. if tempErr != nil {
  241. err = errors.New(fmt.Sprint("获取合同审批记录失败,Err:"+tempErr.Error(), err))
  242. return
  243. }
  244. for i := 0; i < len(contractApprovalList); i++ {
  245. selfContractApprovalRecordMap[contractApprovalList[i].ContractApprovalId] = append(selfContractApprovalRecordMap[contractApprovalList[i].ContractApprovalId], contractApprovalList[i])
  246. }
  247. }
  248. }
  249. for i, v := range list {
  250. // 合同编码
  251. if selfContract, has := selfContractMap[v.ContractId]; has {
  252. list[i].ContractCode = selfContract.ContractCode
  253. }
  254. // 审批人和抄送人
  255. if recordList, ok := selfContractApprovalRecordMap[v.ContractApprovalId]; ok {
  256. keySort := make([]int, 0)
  257. flowNodeMap := make(map[int][]contract.ContractApprovalRecord, 0)
  258. for _, approvalRecord := range recordList {
  259. if tmpFlowNodeList, ok := flowNodeMap[approvalRecord.NodeId]; ok {
  260. flowNodeMap[approvalRecord.NodeId] = append(tmpFlowNodeList, *approvalRecord)
  261. } else {
  262. tmpFlowNodeList := make([]contract.ContractApprovalRecord, 1)
  263. tmpFlowNodeList[0] = *approvalRecord
  264. flowNodeMap[approvalRecord.NodeId] = tmpFlowNodeList
  265. keySort = append(keySort, approvalRecord.NodeId)
  266. }
  267. }
  268. approversList := make([][]string, 0)
  269. ccList := make([][]string, 0)
  270. for _, key := range keySort {
  271. approver := make([]string, 0)
  272. cc := make([]string, 0)
  273. if node, ok := flowNodeMap[key]; ok {
  274. for _, vv := range node {
  275. if vv.NodeType == "check" {
  276. approver = append(approver, vv.ApproveUserName)
  277. } else if vv.NodeType == "cc" {
  278. cc = append(cc, vv.ApproveUserName)
  279. }
  280. }
  281. if len(approver) > 0 {
  282. approversList = append(approversList, approver)
  283. }
  284. if len(cc) > 0 {
  285. ccList = append(ccList, cc)
  286. }
  287. }
  288. }
  289. if len(approversList) > 0 {
  290. list[i].FirstLevelApprovers = strings.Join(approversList[0], ",")
  291. }
  292. if len(ccList) > 0 {
  293. list[i].FirstLevelCC = strings.Join(ccList[0], ",")
  294. }
  295. if len(approversList) > 1 {
  296. list[i].SecondLevelApprovers = strings.Join(approversList[1], ",")
  297. }
  298. if len(ccList) > 1 {
  299. list[i].SecondLevelCC = strings.Join(ccList[1], ",")
  300. }
  301. if len(approversList) > 2 {
  302. list[i].ThirdLevelApprovers = strings.Join(approversList[2], ",")
  303. }
  304. if len(ccList) > 2 {
  305. list[i].ThirdLevelCC = strings.Join(ccList[2], ",")
  306. }
  307. }
  308. }
  309. }
  310. //创建excel
  311. dir, err := os.Executable()
  312. exPath := filepath.Dir(dir)
  313. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  314. xlsxFile := xlsx.NewFile()
  315. if err != nil {
  316. br.Msg = "生成文件失败"
  317. br.ErrMsg = "生成文件失败"
  318. return
  319. }
  320. style := xlsx.NewStyle()
  321. alignment := xlsx.Alignment{
  322. Horizontal: "center",
  323. Vertical: "center",
  324. WrapText: true,
  325. }
  326. style.Alignment = alignment
  327. style.ApplyAlignment = true
  328. sheetName := "审批列表"
  329. sheet, err := xlsxFile.AddSheet(sheetName)
  330. if err != nil {
  331. br.Msg = "新增Sheet失败"
  332. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  333. return
  334. }
  335. //标头
  336. rowTitle := sheet.AddRow()
  337. cellA := rowTitle.AddCell()
  338. cellA.Value = "归属公司"
  339. cellB := rowTitle.AddCell()
  340. cellB.Value = "客户名称"
  341. cellC := rowTitle.AddCell()
  342. cellC.Value = "社会信用码"
  343. cellD := rowTitle.AddCell()
  344. cellD.Value = "用印用途"
  345. cellE := rowTitle.AddCell()
  346. cellE.Value = "合同编号"
  347. cellF := rowTitle.AddCell()
  348. cellF.Value = "合同类型"
  349. cellG := rowTitle.AddCell()
  350. cellG.Value = "加盖印章"
  351. cellH := rowTitle.AddCell()
  352. cellH.Value = "所属销售"
  353. cellI := rowTitle.AddCell()
  354. cellI.Value = "提交时间"
  355. cellJ := rowTitle.AddCell()
  356. cellJ.Value = "用印状态"
  357. cellK := rowTitle.AddCell()
  358. cellK.Value = "一级审批人"
  359. cellL := rowTitle.AddCell()
  360. cellL.Value = "一级抄送人"
  361. cellM := rowTitle.AddCell()
  362. cellM.Value = "二级审批人"
  363. cellN := rowTitle.AddCell()
  364. cellN.Value = "二级抄送人"
  365. cellO := rowTitle.AddCell()
  366. cellO.Value = "三级审批人"
  367. cellP := rowTitle.AddCell()
  368. cellP.Value = "三级抄送人"
  369. for _, v := range list {
  370. row := sheet.AddRow()
  371. cellA := row.AddCell()
  372. cellA.Value = v.AffiliatedCompany
  373. cellB := row.AddCell()
  374. cellB.Value = v.CompanyName
  375. cellC := row.AddCell()
  376. cellC.Value = v.CreditCode
  377. cellD := row.AddCell()
  378. cellD.Value = v.Use
  379. cellE := row.AddCell()
  380. cellE.Value = v.ContractCode
  381. cellF := row.AddCell()
  382. cellF.Value = v.ContractType
  383. cellG := row.AddCell()
  384. cellG.Value = v.SealType
  385. cellH := row.AddCell()
  386. cellH.Value = v.ApplyUserName
  387. cellI := row.AddCell()
  388. cellI.Value = v.CreateTime.Format(utils.FormatDateTime)
  389. cellJ := row.AddCell()
  390. cellJ.Value = v.Status
  391. cellK := row.AddCell()
  392. cellK.Value = v.FirstLevelApprovers
  393. cellL := row.AddCell()
  394. cellL.Value = v.FirstLevelCC
  395. cellM := row.AddCell()
  396. cellM.Value = v.SecondLevelApprovers
  397. cellN := row.AddCell()
  398. cellN.Value = v.SecondLevelCC
  399. cellO := row.AddCell()
  400. cellO.Value = v.ThirdLevelApprovers
  401. cellP := row.AddCell()
  402. cellP.Value = v.ThirdLevelCC
  403. }
  404. err = xlsxFile.Save(downLoadnFilePath)
  405. if err != nil {
  406. br.Msg = "保存文件失败"
  407. br.ErrMsg = "保存文件失败"
  408. return
  409. }
  410. downloadFileName := "用印审批列表" + time.Now().Format("2006.01.02")+ ".xlsx"
  411. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  412. defer func() {
  413. os.Remove(downLoadnFilePath)
  414. }()
  415. br.Success = true
  416. br.Ret = 200
  417. br.IsAddLog = true
  418. }
  419. // 用印申请
  420. // @Title 用印申请
  421. // @Description 用印申请
  422. // @Param request body request.SealApprovalApplyReq true "type json string"
  423. // @Success 200 申请成功
  424. // @router /applySealApproval [post]
  425. func (this *SealApprovalController) Apply() {
  426. br := new(models.BaseResponse).Init()
  427. defer func() {
  428. this.Data["json"] = br
  429. this.ServeJSON()
  430. }()
  431. sysUser := this.SysUser
  432. if sysUser == nil {
  433. br.Msg = "请登录"
  434. br.ErrMsg = "请登录,SysUser is Empty"
  435. br.Ret = 408
  436. return
  437. }
  438. var req request.SealApprovalApplyReq
  439. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  440. if err != nil {
  441. br.Msg = "参数解析异常!"
  442. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  443. return
  444. }
  445. reqVerify := utils.Rules{
  446. "Use": {utils.NotEmpty()},
  447. "CompanyName": {utils.NotEmpty()},
  448. "CreditCode": {utils.NotEmpty()},
  449. "ServiceType": {utils.NotEmpty()},
  450. "SealType": {utils.NotEmpty()},
  451. "FileUrls": {utils.NotEmpty()},
  452. "AffiliatedCompany": {utils.NotEmpty()},
  453. }
  454. err = utils.Verify(req, reqVerify, utils.LANG_CN)
  455. if err != nil {
  456. br.Msg = "参数丢失!"
  457. br.ErrMsg = "参数丢失!Err:" + err.Error()
  458. return
  459. }
  460. // 申请用印
  461. err = seal.ApplySeal(this.SysUser, req)
  462. if err != nil {
  463. br.Msg = "申请用印失败!"
  464. br.ErrMsg = "申请用印失败!Err:" + err.Error()
  465. return
  466. }
  467. br.Ret = 200
  468. br.Success = true
  469. br.Msg = "申请用印成功"
  470. }
  471. // 编辑用印申请
  472. // @Title 编辑用印申请
  473. // @Description 编辑用印申请
  474. // @Param request body request.SealApprovalEditReq true "type json string"
  475. // @Success 200 操作成功
  476. // @router /editSealApproval [post]
  477. func (this *SealApprovalController) Edit() {
  478. br := new(models.BaseResponse).Init()
  479. defer func() {
  480. this.Data["json"] = br
  481. this.ServeJSON()
  482. }()
  483. sysUser := this.SysUser
  484. if sysUser == nil {
  485. br.Msg = "请登录"
  486. br.ErrMsg = "请登录,SysUser is Empty"
  487. br.Ret = 408
  488. return
  489. }
  490. var req request.SealApprovalEditReq
  491. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  492. if err != nil {
  493. br.Msg = "参数解析异常!"
  494. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  495. return
  496. }
  497. if req.SealId <= 0 {
  498. br.Msg = "用印审批ID有误"
  499. br.ErrMsg = "用印审批ID有误"
  500. return
  501. }
  502. if req.Use == "" {
  503. br.Msg = "用印用途不能为空"
  504. br.ErrMsg = "用印用途不能为空"
  505. return
  506. }
  507. if req.CompanyName == "" {
  508. br.Msg = "客户名称不能为空"
  509. br.ErrMsg = "客户名称不能为空"
  510. return
  511. }
  512. if req.CreditCode == "" {
  513. br.Msg = "社会统一信用代码不能为空"
  514. br.ErrMsg = "社会统一信用代码不能为空"
  515. return
  516. }
  517. if req.ServiceType == "" {
  518. br.Msg = "合同类型不能为空"
  519. br.ErrMsg = "合同类型不能为空"
  520. return
  521. }
  522. if req.SealType == "" {
  523. br.Msg = "印章类型不能为空"
  524. br.ErrMsg = "印章类型不能为空"
  525. return
  526. }
  527. if len(req.FileUrls) == 0 {
  528. br.Msg = "合同附件不能为空"
  529. br.ErrMsg = "合同附件不能为空"
  530. return
  531. }
  532. if req.AffiliatedCompany == "" {
  533. br.Msg = "归属公司不能为空"
  534. br.ErrMsg = "归属公司不能为空"
  535. return
  536. }
  537. // 编辑用印
  538. err = seal.EditApply(this.SysUser, req)
  539. if err != nil {
  540. br.Msg = "编辑用印申请失败!"
  541. br.ErrMsg = "编辑用印申请失败!Err:" + err.Error()
  542. return
  543. }
  544. br.Ret = 200
  545. br.Success = true
  546. br.Msg = "编辑用印申请成功"
  547. }
  548. // 审批角色编辑
  549. // @Title 审批角色编辑
  550. // @Description 审批角色编辑
  551. // @Param request body request.SealApprovalEditReq true "type json string"
  552. // @Success 200 操作成功
  553. // @router /verifierEditSealApproval [post]
  554. func (this *SealApprovalController) VerifierEdit() {
  555. br := new(models.BaseResponse).Init()
  556. defer func() {
  557. this.Data["json"] = br
  558. this.ServeJSON()
  559. }()
  560. sysUser := this.SysUser
  561. if sysUser == nil {
  562. br.Msg = "请登录"
  563. br.ErrMsg = "请登录,SysUser is Empty"
  564. br.Ret = 408
  565. return
  566. }
  567. var req request.SealApprovalEditReq
  568. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  569. if err != nil {
  570. br.Msg = "参数解析异常!"
  571. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  572. return
  573. }
  574. if req.SealId <= 0 {
  575. br.Msg = "用印审批ID有误"
  576. br.ErrMsg = "用印审批ID有误"
  577. return
  578. }
  579. if req.Use == "" {
  580. br.Msg = "用印用途不能为空"
  581. br.ErrMsg = "用印用途不能为空"
  582. return
  583. }
  584. if req.CompanyName == "" {
  585. br.Msg = "客户名称不能为空"
  586. br.ErrMsg = "客户名称不能为空"
  587. return
  588. }
  589. if req.CreditCode == "" {
  590. br.Msg = "社会统一信用代码不能为空"
  591. br.ErrMsg = "社会统一信用代码不能为空"
  592. return
  593. }
  594. if req.ServiceType == "" {
  595. br.Msg = "合同类型不能为空"
  596. br.ErrMsg = "合同类型不能为空"
  597. return
  598. }
  599. if req.SealType == "" {
  600. br.Msg = "印章类型不能为空"
  601. br.ErrMsg = "印章类型不能为空"
  602. return
  603. }
  604. if len(req.FileUrls) == 0 {
  605. br.Msg = "合同附件不能为空"
  606. br.ErrMsg = "合同附件不能为空"
  607. return
  608. }
  609. if req.AffiliatedCompany == "" {
  610. br.Msg = "归属公司不能为空"
  611. br.ErrMsg = "归属公司不能为空"
  612. return
  613. }
  614. // 审批者编辑
  615. err = seal.VerifierEditApply(this.SysUser, req)
  616. if err != nil {
  617. br.Msg = "编辑用印申请失败!"
  618. br.ErrMsg = "编辑用印申请失败!Err:" + err.Error()
  619. return
  620. }
  621. br.Ret = 200
  622. br.Success = true
  623. br.Msg = "编辑用印申请成功"
  624. }
  625. // 用印审批详情
  626. // @Title 用印审批详情
  627. // @Description 用印审批详情
  628. // @Param SealId query int false "用印审批ID"
  629. // @Success 200 {object} response.SealApprovalDetail
  630. // @router /getSealApprovalDetail [get]
  631. func (this *SealApprovalController) Detail() {
  632. br := new(models.BaseResponse).Init()
  633. defer func() {
  634. this.Data["json"] = br
  635. this.ServeJSON()
  636. }()
  637. sysUser := this.SysUser
  638. if sysUser == nil {
  639. br.Msg = "请登录"
  640. br.ErrMsg = "请登录,SysUser is Empty"
  641. br.Ret = 408
  642. return
  643. }
  644. sealId, _ := this.GetInt("SealId")
  645. sealInfo, flowNodeListResp, opButton, err := seal.GetSealApprovalDetail(sealId, sysUser)
  646. if err != nil {
  647. br.Msg = "获取用印详情失败"
  648. br.ErrMsg = "获取用印详情失败,Err:" + err.Error()
  649. return
  650. }
  651. br.Ret = 200
  652. br.Success = true
  653. br.Msg = "获取成功"
  654. br.Data = response.SealApprovalDetail{
  655. SealDetail: sealInfo,
  656. FlowNodeList: flowNodeListResp,
  657. OpButton: opButton,
  658. }
  659. }
  660. // 撤回用印申请
  661. // @Title 撤回用印申请
  662. // @Description 撤回用印申请
  663. // @Param request body request.SealApprovalCancelReq true "type json string"
  664. // @Success 200 操作成功
  665. // @router /cancelSealApproval [post]
  666. func (this *SealApprovalController) Cancel() {
  667. br := new(models.BaseResponse).Init()
  668. defer func() {
  669. this.Data["json"] = br
  670. this.ServeJSON()
  671. }()
  672. sysUser := this.SysUser
  673. if sysUser == nil {
  674. br.Msg = "请登录"
  675. br.ErrMsg = "请登录,SysUser is Empty"
  676. br.Ret = 408
  677. return
  678. }
  679. var req request.SealApprovalCancelReq
  680. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  681. if err != nil {
  682. br.Msg = "参数解析异常!"
  683. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  684. return
  685. }
  686. if req.SealId <= 0 {
  687. br.Msg = "参数异常!"
  688. br.ErrMsg = "参数异常!"
  689. return
  690. }
  691. err = seal.CancelSealApproval(req.SealId, sysUser)
  692. if err != nil {
  693. br.Msg = "用印审批撤回失败"
  694. br.ErrMsg = "用印审批撤回失败,Err:" + err.Error()
  695. return
  696. }
  697. br.Ret = 200
  698. br.Success = true
  699. br.Msg = "操作成功"
  700. }
  701. // 删除用印申请
  702. // @Title 删除用印申请
  703. // @Description 删除用印申请
  704. // @Param request body request.SealApprovalDelReq true "type json string"
  705. // @Success 200 操作成功
  706. // @router /delSealApproval [post]
  707. func (this *SealApprovalController) Del() {
  708. br := new(models.BaseResponse).Init()
  709. defer func() {
  710. this.Data["json"] = br
  711. this.ServeJSON()
  712. }()
  713. sysUser := this.SysUser
  714. if sysUser == nil {
  715. br.Msg = "请登录"
  716. br.ErrMsg = "请登录,SysUser is Empty"
  717. br.Ret = 408
  718. return
  719. }
  720. var req request.SealApprovalDelReq
  721. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  722. if err != nil {
  723. br.Msg = "参数解析异常!"
  724. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  725. return
  726. }
  727. if req.SealId <= 0 {
  728. br.Msg = "参数异常!"
  729. br.ErrMsg = "参数异常!"
  730. return
  731. }
  732. err = seal.DelSealApproval(req.SealId, sysUser)
  733. if err != nil {
  734. br.Msg = "用印申请删除失败"
  735. br.ErrMsg = "用印申请删除失败,Err:" + err.Error()
  736. return
  737. }
  738. br.Ret = 200
  739. br.Success = true
  740. br.Msg = "操作成功"
  741. }
  742. // 通过用印申请
  743. // @Title 通过用印申请
  744. // @Description 通过用印申请
  745. // @Param request body request.SealApplyApprovedReq true "type json string"
  746. // @Success 200 操作成功
  747. // @router /approvedSealApproval [post]
  748. func (this *SealApprovalController) Approved() {
  749. br := new(models.BaseResponse).Init()
  750. defer func() {
  751. this.Data["json"] = br
  752. this.ServeJSON()
  753. }()
  754. sysUser := this.SysUser
  755. if sysUser == nil {
  756. br.Msg = "请登录"
  757. br.ErrMsg = "请登录,SysUser is Empty"
  758. br.Ret = 408
  759. return
  760. }
  761. var req request.SealApplyApprovedReq
  762. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  763. if err != nil {
  764. br.Msg = "参数解析异常!"
  765. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  766. return
  767. }
  768. if req.SealId <= 0 {
  769. br.Msg = "参数异常!"
  770. br.ErrMsg = "参数异常!"
  771. return
  772. }
  773. err = seal.ApprovedApproval(req.SealId, sysUser, req.Remark)
  774. if err != nil {
  775. br.Msg = "用印审批失败"
  776. br.ErrMsg = "用印审批失败,Err:" + err.Error()
  777. return
  778. }
  779. br.Ret = 200
  780. br.Success = true
  781. br.Msg = "操作成功"
  782. }
  783. // 驳回用印申请
  784. // @Title 驳回用印申请
  785. // @Description 驳回用印申请
  786. // @Param request body request.SealApplyRejectReq true "type json string"
  787. // @Success 200 操作成功
  788. // @router /rejectSealApproval [post]
  789. func (this *SealApprovalController) Reject() {
  790. br := new(models.BaseResponse).Init()
  791. defer func() {
  792. this.Data["json"] = br
  793. this.ServeJSON()
  794. }()
  795. sysUser := this.SysUser
  796. if sysUser == nil {
  797. br.Msg = "请登录"
  798. br.ErrMsg = "请登录,SysUser is Empty"
  799. br.Ret = 408
  800. return
  801. }
  802. var req request.SealApplyRejectReq
  803. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  804. if err != nil {
  805. br.Msg = "参数解析异常!"
  806. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  807. return
  808. }
  809. if req.SealId <= 0 {
  810. br.Msg = "参数异常!"
  811. br.ErrMsg = "参数异常!"
  812. return
  813. }
  814. remark := strings.Trim(req.Remark, " ")
  815. if remark == "" {
  816. br.Msg = "请输入驳回理由"
  817. br.ErrMsg = "请输入驳回理由"
  818. return
  819. }
  820. err = seal.RejectApproval(req.SealId, sysUser, remark)
  821. if err != nil {
  822. br.Msg = "用印驳回失败"
  823. br.ErrMsg = "用印驳回失败,Err:" + err.Error()
  824. return
  825. }
  826. br.Ret = 200
  827. br.Success = true
  828. br.Msg = "操作成功"
  829. }
  830. // 作废用印申请
  831. // @Title 作废用印申请
  832. // @Description 作废用印申请
  833. // @Param request body request.SealApplyInvalidReq true "type json string"
  834. // @Success 200 操作成功
  835. // @router /invalidSealApproval [post]
  836. func (this *SealApprovalController) Invalid() {
  837. br := new(models.BaseResponse).Init()
  838. defer func() {
  839. this.Data["json"] = br
  840. this.ServeJSON()
  841. }()
  842. sysUser := this.SysUser
  843. if sysUser == nil {
  844. br.Msg = "请登录"
  845. br.ErrMsg = "请登录,SysUser is Empty"
  846. br.Ret = 408
  847. return
  848. }
  849. var req request.SealApprovalInvalidReq
  850. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  851. if err != nil {
  852. br.Msg = "参数解析异常!"
  853. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  854. return
  855. }
  856. if req.SealId <= 0 {
  857. br.Msg = "参数异常!"
  858. br.ErrMsg = "参数异常!"
  859. return
  860. }
  861. err = seal.InvalidSealApproval(req.SealId, sysUser)
  862. if err != nil {
  863. br.Msg = "用印作废失败"
  864. br.ErrMsg = "用印作废失败,Err:" + err.Error()
  865. return
  866. }
  867. br.Ret = 200
  868. br.Success = true
  869. br.Msg = "操作成功"
  870. }
  871. // OperationList
  872. // @Title 用印操作日志列表
  873. // @Description 用印操作日志列表接口
  874. // @Param SealId query int true "用印申请ID"
  875. // @Success 200 {object} response.SealOperationListResp
  876. // @router /getOperationList [get]
  877. func (this *SealApprovalController) OperationList() {
  878. br := new(models.BaseResponse).Init()
  879. defer func() {
  880. this.Data["json"] = br
  881. this.ServeJSON()
  882. }()
  883. sysUser := this.SysUser
  884. if sysUser == nil {
  885. br.Msg = "请登录"
  886. br.ErrMsg = "请登录,SysUser is Empty"
  887. br.Ret = 408
  888. return
  889. }
  890. reqSealId, _ := this.GetInt("SealId", 0)
  891. if reqSealId <= 0 {
  892. br.Msg = "用印申请编号获取失败!"
  893. br.ErrMsg = "用印申请编号获取失败!"
  894. return
  895. }
  896. list, err := seal.GetSealOperationRecordList(reqSealId)
  897. if err != nil {
  898. br.Msg = "获取列表失败!"
  899. br.ErrMsg = "获取列表失败!"
  900. return
  901. }
  902. br.Ret = 200
  903. br.Msg = "获取成功"
  904. br.Success = true
  905. br.Data = response.SealOperationListResp{
  906. List: list,
  907. }
  908. }
  909. // 关联公司列表
  910. // @Title 关联公司列表
  911. // @Description 关联公司列表
  912. // @Success 200 {object} response.SealApprovalListResp
  913. // @router /getAffiliatedCompany [get]
  914. func (this *SealApprovalController) AffiliatedCompanyList() {
  915. br := new(models.BaseResponse).Init()
  916. defer func() {
  917. this.Data["json"] = br
  918. this.ServeJSON()
  919. }()
  920. sysUser := this.SysUser
  921. if sysUser == nil {
  922. br.Msg = "请登录"
  923. br.ErrMsg = "请登录,SysUser is Empty"
  924. br.Ret = 408
  925. return
  926. }
  927. crmConfig, err := company.GetConfigDetailByCode("affiliated_company")
  928. if err != nil {
  929. br.Msg = "获取配置失败"
  930. br.ErrMsg = "获取配置失败"
  931. br.IsSendEmail = false
  932. return
  933. }
  934. list := strings.Split(crmConfig.ConfigValue, ",")
  935. br.Ret = 200
  936. br.Success = true
  937. br.Msg = "获取成功"
  938. br.Data = list
  939. }