seal_approval.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  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 := "审批列表" + ".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. // 审批者编辑
  610. err = seal.VerifierEditApply(this.SysUser, req)
  611. if err != nil {
  612. br.Msg = "编辑用印申请失败!"
  613. br.ErrMsg = "编辑用印申请失败!Err:" + err.Error()
  614. return
  615. }
  616. br.Ret = 200
  617. br.Success = true
  618. br.Msg = "编辑用印申请成功"
  619. }
  620. // 用印审批详情
  621. // @Title 用印审批详情
  622. // @Description 用印审批详情
  623. // @Param SealId query int false "用印审批ID"
  624. // @Success 200 {object} response.SealApprovalDetail
  625. // @router /getSealApprovalDetail [get]
  626. func (this *SealApprovalController) Detail() {
  627. br := new(models.BaseResponse).Init()
  628. defer func() {
  629. this.Data["json"] = br
  630. this.ServeJSON()
  631. }()
  632. sysUser := this.SysUser
  633. if sysUser == nil {
  634. br.Msg = "请登录"
  635. br.ErrMsg = "请登录,SysUser is Empty"
  636. br.Ret = 408
  637. return
  638. }
  639. sealId, _ := this.GetInt("SealId")
  640. sealInfo, flowNodeListResp, opButton, err := seal.GetSealApprovalDetail(sealId, sysUser)
  641. if err != nil {
  642. br.Msg = "获取用印详情失败"
  643. br.ErrMsg = "获取用印详情失败,Err:" + err.Error()
  644. return
  645. }
  646. br.Ret = 200
  647. br.Success = true
  648. br.Msg = "获取成功"
  649. br.Data = response.SealApprovalDetail{
  650. SealDetail: sealInfo,
  651. FlowNodeList: flowNodeListResp,
  652. OpButton: opButton,
  653. }
  654. }
  655. // 撤回用印申请
  656. // @Title 撤回用印申请
  657. // @Description 撤回用印申请
  658. // @Param request body request.SealApprovalCancelReq true "type json string"
  659. // @Success 200 操作成功
  660. // @router /cancelSealApproval [post]
  661. func (this *SealApprovalController) Cancel() {
  662. br := new(models.BaseResponse).Init()
  663. defer func() {
  664. this.Data["json"] = br
  665. this.ServeJSON()
  666. }()
  667. sysUser := this.SysUser
  668. if sysUser == nil {
  669. br.Msg = "请登录"
  670. br.ErrMsg = "请登录,SysUser is Empty"
  671. br.Ret = 408
  672. return
  673. }
  674. var req request.SealApprovalCancelReq
  675. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  676. if err != nil {
  677. br.Msg = "参数解析异常!"
  678. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  679. return
  680. }
  681. if req.SealId <= 0 {
  682. br.Msg = "参数异常!"
  683. br.ErrMsg = "参数异常!"
  684. return
  685. }
  686. err = seal.CancelSealApproval(req.SealId, sysUser)
  687. if err != nil {
  688. br.Msg = "用印审批撤回失败"
  689. br.ErrMsg = "用印审批撤回失败,Err:" + err.Error()
  690. return
  691. }
  692. br.Ret = 200
  693. br.Success = true
  694. br.Msg = "操作成功"
  695. }
  696. // 删除用印申请
  697. // @Title 删除用印申请
  698. // @Description 删除用印申请
  699. // @Param request body request.SealApprovalDelReq true "type json string"
  700. // @Success 200 操作成功
  701. // @router /delSealApproval [post]
  702. func (this *SealApprovalController) Del() {
  703. br := new(models.BaseResponse).Init()
  704. defer func() {
  705. this.Data["json"] = br
  706. this.ServeJSON()
  707. }()
  708. sysUser := this.SysUser
  709. if sysUser == nil {
  710. br.Msg = "请登录"
  711. br.ErrMsg = "请登录,SysUser is Empty"
  712. br.Ret = 408
  713. return
  714. }
  715. var req request.SealApprovalDelReq
  716. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  717. if err != nil {
  718. br.Msg = "参数解析异常!"
  719. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  720. return
  721. }
  722. if req.SealId <= 0 {
  723. br.Msg = "参数异常!"
  724. br.ErrMsg = "参数异常!"
  725. return
  726. }
  727. err = seal.DelSealApproval(req.SealId, sysUser)
  728. if err != nil {
  729. br.Msg = "用印申请删除失败"
  730. br.ErrMsg = "用印申请删除失败,Err:" + err.Error()
  731. return
  732. }
  733. br.Ret = 200
  734. br.Success = true
  735. br.Msg = "操作成功"
  736. }
  737. // 通过用印申请
  738. // @Title 通过用印申请
  739. // @Description 通过用印申请
  740. // @Param request body request.SealApplyApprovedReq true "type json string"
  741. // @Success 200 操作成功
  742. // @router /approvedSealApproval [post]
  743. func (this *SealApprovalController) Approved() {
  744. br := new(models.BaseResponse).Init()
  745. defer func() {
  746. this.Data["json"] = br
  747. this.ServeJSON()
  748. }()
  749. sysUser := this.SysUser
  750. if sysUser == nil {
  751. br.Msg = "请登录"
  752. br.ErrMsg = "请登录,SysUser is Empty"
  753. br.Ret = 408
  754. return
  755. }
  756. var req request.SealApplyApprovedReq
  757. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  758. if err != nil {
  759. br.Msg = "参数解析异常!"
  760. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  761. return
  762. }
  763. if req.SealId <= 0 {
  764. br.Msg = "参数异常!"
  765. br.ErrMsg = "参数异常!"
  766. return
  767. }
  768. err = seal.ApprovedApproval(req.SealId, sysUser, req.Remark)
  769. if err != nil {
  770. br.Msg = "用印审批失败"
  771. br.ErrMsg = "用印审批失败,Err:" + err.Error()
  772. return
  773. }
  774. br.Ret = 200
  775. br.Success = true
  776. br.Msg = "操作成功"
  777. }
  778. // 驳回用印申请
  779. // @Title 驳回用印申请
  780. // @Description 驳回用印申请
  781. // @Param request body request.SealApplyRejectReq true "type json string"
  782. // @Success 200 操作成功
  783. // @router /rejectSealApproval [post]
  784. func (this *SealApprovalController) Reject() {
  785. br := new(models.BaseResponse).Init()
  786. defer func() {
  787. this.Data["json"] = br
  788. this.ServeJSON()
  789. }()
  790. sysUser := this.SysUser
  791. if sysUser == nil {
  792. br.Msg = "请登录"
  793. br.ErrMsg = "请登录,SysUser is Empty"
  794. br.Ret = 408
  795. return
  796. }
  797. var req request.SealApplyRejectReq
  798. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  799. if err != nil {
  800. br.Msg = "参数解析异常!"
  801. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  802. return
  803. }
  804. if req.SealId <= 0 {
  805. br.Msg = "参数异常!"
  806. br.ErrMsg = "参数异常!"
  807. return
  808. }
  809. remark := strings.Trim(req.Remark, " ")
  810. if remark == "" {
  811. br.Msg = "请输入驳回理由"
  812. br.ErrMsg = "请输入驳回理由"
  813. return
  814. }
  815. err = seal.RejectApproval(req.SealId, sysUser, remark)
  816. if err != nil {
  817. br.Msg = "用印驳回失败"
  818. br.ErrMsg = "用印驳回失败,Err:" + err.Error()
  819. return
  820. }
  821. br.Ret = 200
  822. br.Success = true
  823. br.Msg = "操作成功"
  824. }
  825. // 作废用印申请
  826. // @Title 作废用印申请
  827. // @Description 作废用印申请
  828. // @Param request body request.SealApplyInvalidReq true "type json string"
  829. // @Success 200 操作成功
  830. // @router /invalidSealApproval [post]
  831. func (this *SealApprovalController) Invalid() {
  832. br := new(models.BaseResponse).Init()
  833. defer func() {
  834. this.Data["json"] = br
  835. this.ServeJSON()
  836. }()
  837. sysUser := this.SysUser
  838. if sysUser == nil {
  839. br.Msg = "请登录"
  840. br.ErrMsg = "请登录,SysUser is Empty"
  841. br.Ret = 408
  842. return
  843. }
  844. var req request.SealApprovalInvalidReq
  845. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  846. if err != nil {
  847. br.Msg = "参数解析异常!"
  848. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  849. return
  850. }
  851. if req.SealId <= 0 {
  852. br.Msg = "参数异常!"
  853. br.ErrMsg = "参数异常!"
  854. return
  855. }
  856. err = seal.InvalidSealApproval(req.SealId, sysUser)
  857. if err != nil {
  858. br.Msg = "用印作废失败"
  859. br.ErrMsg = "用印作废失败,Err:" + err.Error()
  860. return
  861. }
  862. br.Ret = 200
  863. br.Success = true
  864. br.Msg = "操作成功"
  865. }
  866. // OperationList
  867. // @Title 用印操作日志列表
  868. // @Description 用印操作日志列表接口
  869. // @Param SealId query int true "用印申请ID"
  870. // @Success 200 {object} response.SealOperationListResp
  871. // @router /getOperationList [get]
  872. func (this *SealApprovalController) OperationList() {
  873. br := new(models.BaseResponse).Init()
  874. defer func() {
  875. this.Data["json"] = br
  876. this.ServeJSON()
  877. }()
  878. sysUser := this.SysUser
  879. if sysUser == nil {
  880. br.Msg = "请登录"
  881. br.ErrMsg = "请登录,SysUser is Empty"
  882. br.Ret = 408
  883. return
  884. }
  885. reqSealId, _ := this.GetInt("SealId", 0)
  886. if reqSealId <= 0 {
  887. br.Msg = "用印申请编号获取失败!"
  888. br.ErrMsg = "用印申请编号获取失败!"
  889. return
  890. }
  891. list, err := seal.GetSealOperationRecordList(reqSealId)
  892. if err != nil {
  893. br.Msg = "获取列表失败!"
  894. br.ErrMsg = "获取列表失败!"
  895. return
  896. }
  897. br.Ret = 200
  898. br.Msg = "获取成功"
  899. br.Success = true
  900. br.Data = response.SealOperationListResp{
  901. List: list,
  902. }
  903. }
  904. // 关联公司列表
  905. // @Title 关联公司列表
  906. // @Description 关联公司列表
  907. // @Success 200 {object} response.SealApprovalListResp
  908. // @router /getAffiliatedCompany [get]
  909. func (this *SealApprovalController) AffiliatedCompanyList() {
  910. br := new(models.BaseResponse).Init()
  911. defer func() {
  912. this.Data["json"] = br
  913. this.ServeJSON()
  914. }()
  915. sysUser := this.SysUser
  916. if sysUser == nil {
  917. br.Msg = "请登录"
  918. br.ErrMsg = "请登录,SysUser is Empty"
  919. br.Ret = 408
  920. return
  921. }
  922. crmConfig, err := company.GetConfigDetailByCode("affiliated_company")
  923. if err != nil {
  924. br.Msg = "获取配置失败"
  925. br.ErrMsg = "获取配置失败"
  926. br.IsSendEmail = false
  927. return
  928. }
  929. list := strings.Split(crmConfig.ConfigValue, ",")
  930. br.Ret = 200
  931. br.Success = true
  932. br.Msg = "获取成功"
  933. br.Data = list
  934. }