seal_approval.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  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. for ii, key := range keySort {
  269. if ii == 0 {
  270. if node, ok := flowNodeMap[key]; ok {
  271. for _, vv := range node {
  272. if vv.NodeType == "check" {
  273. list[i].FirstLevelApprovers += vv.ApproveUserName + ","
  274. }
  275. }
  276. }
  277. } else {
  278. if node, ok := flowNodeMap[key]; ok {
  279. for _, vv := range node {
  280. if vv.NodeType == "check" {
  281. list[i].SecondLevelApprovers += vv.ApproveUserName + ","
  282. } else if vv.NodeType == "cc" && list[i].FirstLevelCC == "" {
  283. list[i].FirstLevelCC += vv.ApproveUserName + ","
  284. } else {
  285. list[i].SecondLevelCC += vv.ApproveUserName + ","
  286. }
  287. }
  288. }
  289. }
  290. }
  291. list[i].FirstLevelApprovers = strings.TrimRight(list[i].FirstLevelApprovers, ",")
  292. list[i].FirstLevelCC = strings.TrimRight(list[i].FirstLevelCC, ",")
  293. list[i].SecondLevelApprovers = strings.TrimRight(list[i].SecondLevelApprovers, ",")
  294. list[i].SecondLevelCC = strings.TrimRight(list[i].SecondLevelCC, ",")
  295. }
  296. }
  297. }
  298. //创建excel
  299. dir, err := os.Executable()
  300. exPath := filepath.Dir(dir)
  301. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  302. xlsxFile := xlsx.NewFile()
  303. if err != nil {
  304. br.Msg = "生成文件失败"
  305. br.ErrMsg = "生成文件失败"
  306. return
  307. }
  308. style := xlsx.NewStyle()
  309. alignment := xlsx.Alignment{
  310. Horizontal: "center",
  311. Vertical: "center",
  312. WrapText: true,
  313. }
  314. style.Alignment = alignment
  315. style.ApplyAlignment = true
  316. sheetName := "审批列表"
  317. sheet, err := xlsxFile.AddSheet(sheetName)
  318. if err != nil {
  319. br.Msg = "新增Sheet失败"
  320. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  321. return
  322. }
  323. //标头
  324. rowTitle := sheet.AddRow()
  325. cellA := rowTitle.AddCell()
  326. cellA.Value = "归属公司"
  327. cellB := rowTitle.AddCell()
  328. cellB.Value = "客户名称"
  329. cellC := rowTitle.AddCell()
  330. cellC.Value = "社会信用码"
  331. cellD := rowTitle.AddCell()
  332. cellD.Value = "用印用途"
  333. cellE := rowTitle.AddCell()
  334. cellE.Value = "合同编号"
  335. cellF := rowTitle.AddCell()
  336. cellF.Value = "合同类型"
  337. cellG := rowTitle.AddCell()
  338. cellG.Value = "加盖印章"
  339. cellH := rowTitle.AddCell()
  340. cellH.Value = "所属销售"
  341. cellI := rowTitle.AddCell()
  342. cellI.Value = "提交时间"
  343. cellJ := rowTitle.AddCell()
  344. cellJ.Value = "用印状态"
  345. cellK := rowTitle.AddCell()
  346. cellK.Value = "一级审批人"
  347. cellL := rowTitle.AddCell()
  348. cellL.Value = "一级抄送人"
  349. cellM := rowTitle.AddCell()
  350. cellM.Value = "二级审批人"
  351. cellN := rowTitle.AddCell()
  352. cellN.Value = "二级抄送人"
  353. for _, v := range list {
  354. row := sheet.AddRow()
  355. cellA := row.AddCell()
  356. cellA.Value = v.AffiliatedCompany
  357. cellB := row.AddCell()
  358. cellB.Value = v.CompanyName
  359. cellC := row.AddCell()
  360. cellC.Value = v.CreditCode
  361. cellD := row.AddCell()
  362. cellD.Value = v.Use
  363. cellE := row.AddCell()
  364. cellE.Value = v.ContractCode
  365. cellF := row.AddCell()
  366. cellF.Value = v.ContractType
  367. cellG := row.AddCell()
  368. cellG.Value = v.SealType
  369. cellH := row.AddCell()
  370. cellH.Value = v.ApplyUserName
  371. cellI := row.AddCell()
  372. cellI.Value = v.CreateTime.Format(utils.FormatDateTime)
  373. cellJ := row.AddCell()
  374. cellJ.Value = v.Status
  375. cellK := row.AddCell()
  376. cellK.Value = v.FirstLevelApprovers
  377. cellL := row.AddCell()
  378. cellL.Value = v.FirstLevelCC
  379. cellM := row.AddCell()
  380. cellM.Value = v.SecondLevelApprovers
  381. cellN := row.AddCell()
  382. cellN.Value = v.SecondLevelCC
  383. }
  384. err = xlsxFile.Save(downLoadnFilePath)
  385. if err != nil {
  386. br.Msg = "保存文件失败"
  387. br.ErrMsg = "保存文件失败"
  388. return
  389. }
  390. downloadFileName := "审批列表" + ".xlsx"
  391. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  392. defer func() {
  393. os.Remove(downLoadnFilePath)
  394. }()
  395. br.Success = true
  396. br.Ret = 200
  397. br.IsAddLog = true
  398. }
  399. // 用印申请
  400. // @Title 用印申请
  401. // @Description 用印申请
  402. // @Param request body request.SealApprovalApplyReq true "type json string"
  403. // @Success 200 申请成功
  404. // @router /applySealApproval [post]
  405. func (this *SealApprovalController) Apply() {
  406. br := new(models.BaseResponse).Init()
  407. defer func() {
  408. this.Data["json"] = br
  409. this.ServeJSON()
  410. }()
  411. sysUser := this.SysUser
  412. if sysUser == nil {
  413. br.Msg = "请登录"
  414. br.ErrMsg = "请登录,SysUser is Empty"
  415. br.Ret = 408
  416. return
  417. }
  418. var req request.SealApprovalApplyReq
  419. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  420. if err != nil {
  421. br.Msg = "参数解析异常!"
  422. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  423. return
  424. }
  425. reqVerify := utils.Rules{
  426. "Use": {utils.NotEmpty()},
  427. "CompanyName": {utils.NotEmpty()},
  428. "CreditCode": {utils.NotEmpty()},
  429. "ServiceType": {utils.NotEmpty()},
  430. "SealType": {utils.NotEmpty()},
  431. "FileUrls": {utils.NotEmpty()},
  432. "AffiliatedCompany": {utils.NotEmpty()},
  433. }
  434. err = utils.Verify(req, reqVerify, utils.LANG_CN)
  435. if err != nil {
  436. br.Msg = "参数丢失!"
  437. br.ErrMsg = "参数丢失!Err:" + err.Error()
  438. return
  439. }
  440. // 申请用印
  441. err = seal.ApplySeal(this.SysUser, req)
  442. if err != nil {
  443. br.Msg = "申请用印失败!"
  444. br.ErrMsg = "申请用印失败!Err:" + err.Error()
  445. return
  446. }
  447. br.Ret = 200
  448. br.Success = true
  449. br.Msg = "申请用印成功"
  450. }
  451. // 编辑用印申请
  452. // @Title 编辑用印申请
  453. // @Description 编辑用印申请
  454. // @Param request body request.SealApprovalEditReq true "type json string"
  455. // @Success 200 操作成功
  456. // @router /editSealApproval [post]
  457. func (this *SealApprovalController) Edit() {
  458. br := new(models.BaseResponse).Init()
  459. defer func() {
  460. this.Data["json"] = br
  461. this.ServeJSON()
  462. }()
  463. sysUser := this.SysUser
  464. if sysUser == nil {
  465. br.Msg = "请登录"
  466. br.ErrMsg = "请登录,SysUser is Empty"
  467. br.Ret = 408
  468. return
  469. }
  470. var req request.SealApprovalEditReq
  471. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  472. if err != nil {
  473. br.Msg = "参数解析异常!"
  474. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  475. return
  476. }
  477. if req.SealId <= 0 {
  478. br.Msg = "用印审批ID有误"
  479. br.ErrMsg = "用印审批ID有误"
  480. return
  481. }
  482. if req.Use == "" {
  483. br.Msg = "用印用途不能为空"
  484. br.ErrMsg = "用印用途不能为空"
  485. return
  486. }
  487. if req.CompanyName == "" {
  488. br.Msg = "客户名称不能为空"
  489. br.ErrMsg = "客户名称不能为空"
  490. return
  491. }
  492. if req.CreditCode == "" {
  493. br.Msg = "社会统一信用代码不能为空"
  494. br.ErrMsg = "社会统一信用代码不能为空"
  495. return
  496. }
  497. if req.ServiceType == "" {
  498. br.Msg = "合同类型不能为空"
  499. br.ErrMsg = "合同类型不能为空"
  500. return
  501. }
  502. if req.SealType == "" {
  503. br.Msg = "印章类型不能为空"
  504. br.ErrMsg = "印章类型不能为空"
  505. return
  506. }
  507. if len(req.FileUrls) == 0 {
  508. br.Msg = "合同附件不能为空"
  509. br.ErrMsg = "合同附件不能为空"
  510. return
  511. }
  512. if req.AffiliatedCompany == "" {
  513. br.Msg = "归属公司不能为空"
  514. br.ErrMsg = "归属公司不能为空"
  515. return
  516. }
  517. // 编辑用印
  518. err = seal.EditApply(this.SysUser, req)
  519. if err != nil {
  520. br.Msg = "编辑用印申请失败!"
  521. br.ErrMsg = "编辑用印申请失败!Err:" + err.Error()
  522. return
  523. }
  524. br.Ret = 200
  525. br.Success = true
  526. br.Msg = "编辑用印申请成功"
  527. }
  528. // 审批角色编辑
  529. // @Title 审批角色编辑
  530. // @Description 审批角色编辑
  531. // @Param request body request.SealApprovalEditReq true "type json string"
  532. // @Success 200 操作成功
  533. // @router /verifierEditSealApproval [post]
  534. func (this *SealApprovalController) VerifierEdit() {
  535. br := new(models.BaseResponse).Init()
  536. defer func() {
  537. this.Data["json"] = br
  538. this.ServeJSON()
  539. }()
  540. sysUser := this.SysUser
  541. if sysUser == nil {
  542. br.Msg = "请登录"
  543. br.ErrMsg = "请登录,SysUser is Empty"
  544. br.Ret = 408
  545. return
  546. }
  547. var req request.SealApprovalEditReq
  548. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  549. if err != nil {
  550. br.Msg = "参数解析异常!"
  551. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  552. return
  553. }
  554. if req.SealId <= 0 {
  555. br.Msg = "用印审批ID有误"
  556. br.ErrMsg = "用印审批ID有误"
  557. return
  558. }
  559. if req.Use == "" {
  560. br.Msg = "用印用途不能为空"
  561. br.ErrMsg = "用印用途不能为空"
  562. return
  563. }
  564. if req.CompanyName == "" {
  565. br.Msg = "客户名称不能为空"
  566. br.ErrMsg = "客户名称不能为空"
  567. return
  568. }
  569. if req.CreditCode == "" {
  570. br.Msg = "社会统一信用代码不能为空"
  571. br.ErrMsg = "社会统一信用代码不能为空"
  572. return
  573. }
  574. if req.ServiceType == "" {
  575. br.Msg = "合同类型不能为空"
  576. br.ErrMsg = "合同类型不能为空"
  577. return
  578. }
  579. if req.SealType == "" {
  580. br.Msg = "印章类型不能为空"
  581. br.ErrMsg = "印章类型不能为空"
  582. return
  583. }
  584. if len(req.FileUrls) == 0 {
  585. br.Msg = "合同附件不能为空"
  586. br.ErrMsg = "合同附件不能为空"
  587. return
  588. }
  589. // 审批者编辑
  590. err = seal.VerifierEditApply(this.SysUser, req)
  591. if err != nil {
  592. br.Msg = "编辑用印申请失败!"
  593. br.ErrMsg = "编辑用印申请失败!Err:" + err.Error()
  594. return
  595. }
  596. br.Ret = 200
  597. br.Success = true
  598. br.Msg = "编辑用印申请成功"
  599. }
  600. // 用印审批详情
  601. // @Title 用印审批详情
  602. // @Description 用印审批详情
  603. // @Param SealId query int false "用印审批ID"
  604. // @Success 200 {object} response.SealApprovalDetail
  605. // @router /getSealApprovalDetail [get]
  606. func (this *SealApprovalController) Detail() {
  607. br := new(models.BaseResponse).Init()
  608. defer func() {
  609. this.Data["json"] = br
  610. this.ServeJSON()
  611. }()
  612. sysUser := this.SysUser
  613. if sysUser == nil {
  614. br.Msg = "请登录"
  615. br.ErrMsg = "请登录,SysUser is Empty"
  616. br.Ret = 408
  617. return
  618. }
  619. sealId, _ := this.GetInt("SealId")
  620. sealInfo, flowNodeListResp, opButton, err := seal.GetSealApprovalDetail(sealId, sysUser)
  621. if err != nil {
  622. br.Msg = "获取用印详情失败"
  623. br.ErrMsg = "获取用印详情失败,Err:" + err.Error()
  624. return
  625. }
  626. br.Ret = 200
  627. br.Success = true
  628. br.Msg = "获取成功"
  629. br.Data = response.SealApprovalDetail{
  630. SealDetail: sealInfo,
  631. FlowNodeList: flowNodeListResp,
  632. OpButton: opButton,
  633. }
  634. }
  635. // 撤回用印申请
  636. // @Title 撤回用印申请
  637. // @Description 撤回用印申请
  638. // @Param request body request.SealApprovalCancelReq true "type json string"
  639. // @Success 200 操作成功
  640. // @router /cancelSealApproval [post]
  641. func (this *SealApprovalController) Cancel() {
  642. br := new(models.BaseResponse).Init()
  643. defer func() {
  644. this.Data["json"] = br
  645. this.ServeJSON()
  646. }()
  647. sysUser := this.SysUser
  648. if sysUser == nil {
  649. br.Msg = "请登录"
  650. br.ErrMsg = "请登录,SysUser is Empty"
  651. br.Ret = 408
  652. return
  653. }
  654. var req request.SealApprovalCancelReq
  655. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  656. if err != nil {
  657. br.Msg = "参数解析异常!"
  658. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  659. return
  660. }
  661. if req.SealId <= 0 {
  662. br.Msg = "参数异常!"
  663. br.ErrMsg = "参数异常!"
  664. return
  665. }
  666. err = seal.CancelSealApproval(req.SealId, sysUser)
  667. if err != nil {
  668. br.Msg = "用印审批撤回失败"
  669. br.ErrMsg = "用印审批撤回失败,Err:" + err.Error()
  670. return
  671. }
  672. br.Ret = 200
  673. br.Success = true
  674. br.Msg = "操作成功"
  675. }
  676. // 删除用印申请
  677. // @Title 删除用印申请
  678. // @Description 删除用印申请
  679. // @Param request body request.SealApprovalDelReq true "type json string"
  680. // @Success 200 操作成功
  681. // @router /delSealApproval [post]
  682. func (this *SealApprovalController) Del() {
  683. br := new(models.BaseResponse).Init()
  684. defer func() {
  685. this.Data["json"] = br
  686. this.ServeJSON()
  687. }()
  688. sysUser := this.SysUser
  689. if sysUser == nil {
  690. br.Msg = "请登录"
  691. br.ErrMsg = "请登录,SysUser is Empty"
  692. br.Ret = 408
  693. return
  694. }
  695. var req request.SealApprovalDelReq
  696. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  697. if err != nil {
  698. br.Msg = "参数解析异常!"
  699. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  700. return
  701. }
  702. if req.SealId <= 0 {
  703. br.Msg = "参数异常!"
  704. br.ErrMsg = "参数异常!"
  705. return
  706. }
  707. err = seal.DelSealApproval(req.SealId, sysUser)
  708. if err != nil {
  709. br.Msg = "用印申请删除失败"
  710. br.ErrMsg = "用印申请删除失败,Err:" + err.Error()
  711. return
  712. }
  713. br.Ret = 200
  714. br.Success = true
  715. br.Msg = "操作成功"
  716. }
  717. // 通过用印申请
  718. // @Title 通过用印申请
  719. // @Description 通过用印申请
  720. // @Param request body request.SealApplyApprovedReq true "type json string"
  721. // @Success 200 操作成功
  722. // @router /approvedSealApproval [post]
  723. func (this *SealApprovalController) Approved() {
  724. br := new(models.BaseResponse).Init()
  725. defer func() {
  726. this.Data["json"] = br
  727. this.ServeJSON()
  728. }()
  729. sysUser := this.SysUser
  730. if sysUser == nil {
  731. br.Msg = "请登录"
  732. br.ErrMsg = "请登录,SysUser is Empty"
  733. br.Ret = 408
  734. return
  735. }
  736. var req request.SealApplyApprovedReq
  737. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  738. if err != nil {
  739. br.Msg = "参数解析异常!"
  740. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  741. return
  742. }
  743. if req.SealId <= 0 {
  744. br.Msg = "参数异常!"
  745. br.ErrMsg = "参数异常!"
  746. return
  747. }
  748. err = seal.ApprovedApproval(req.SealId, sysUser, req.Remark)
  749. if err != nil {
  750. br.Msg = "用印审批失败"
  751. br.ErrMsg = "用印审批失败,Err:" + err.Error()
  752. return
  753. }
  754. br.Ret = 200
  755. br.Success = true
  756. br.Msg = "操作成功"
  757. }
  758. // 驳回用印申请
  759. // @Title 驳回用印申请
  760. // @Description 驳回用印申请
  761. // @Param request body request.SealApplyRejectReq true "type json string"
  762. // @Success 200 操作成功
  763. // @router /rejectSealApproval [post]
  764. func (this *SealApprovalController) Reject() {
  765. br := new(models.BaseResponse).Init()
  766. defer func() {
  767. this.Data["json"] = br
  768. this.ServeJSON()
  769. }()
  770. sysUser := this.SysUser
  771. if sysUser == nil {
  772. br.Msg = "请登录"
  773. br.ErrMsg = "请登录,SysUser is Empty"
  774. br.Ret = 408
  775. return
  776. }
  777. var req request.SealApplyRejectReq
  778. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  779. if err != nil {
  780. br.Msg = "参数解析异常!"
  781. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  782. return
  783. }
  784. if req.SealId <= 0 {
  785. br.Msg = "参数异常!"
  786. br.ErrMsg = "参数异常!"
  787. return
  788. }
  789. remark := strings.Trim(req.Remark, " ")
  790. if remark == "" {
  791. br.Msg = "请输入驳回理由"
  792. br.ErrMsg = "请输入驳回理由"
  793. return
  794. }
  795. err = seal.RejectApproval(req.SealId, sysUser, remark)
  796. if err != nil {
  797. br.Msg = "用印驳回失败"
  798. br.ErrMsg = "用印驳回失败,Err:" + err.Error()
  799. return
  800. }
  801. br.Ret = 200
  802. br.Success = true
  803. br.Msg = "操作成功"
  804. }
  805. // 作废用印申请
  806. // @Title 作废用印申请
  807. // @Description 作废用印申请
  808. // @Param request body request.SealApplyInvalidReq true "type json string"
  809. // @Success 200 操作成功
  810. // @router /invalidSealApproval [post]
  811. func (this *SealApprovalController) Invalid() {
  812. br := new(models.BaseResponse).Init()
  813. defer func() {
  814. this.Data["json"] = br
  815. this.ServeJSON()
  816. }()
  817. sysUser := this.SysUser
  818. if sysUser == nil {
  819. br.Msg = "请登录"
  820. br.ErrMsg = "请登录,SysUser is Empty"
  821. br.Ret = 408
  822. return
  823. }
  824. var req request.SealApprovalInvalidReq
  825. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  826. if err != nil {
  827. br.Msg = "参数解析异常!"
  828. br.ErrMsg = "参数解析异常!Err:" + err.Error()
  829. return
  830. }
  831. if req.SealId <= 0 {
  832. br.Msg = "参数异常!"
  833. br.ErrMsg = "参数异常!"
  834. return
  835. }
  836. err = seal.InvalidSealApproval(req.SealId, sysUser)
  837. if err != nil {
  838. br.Msg = "用印作废失败"
  839. br.ErrMsg = "用印作废失败,Err:" + err.Error()
  840. return
  841. }
  842. br.Ret = 200
  843. br.Success = true
  844. br.Msg = "操作成功"
  845. }
  846. // OperationList
  847. // @Title 用印操作日志列表
  848. // @Description 用印操作日志列表接口
  849. // @Param SealId query int true "用印申请ID"
  850. // @Success 200 {object} response.SealOperationListResp
  851. // @router /getOperationList [get]
  852. func (this *SealApprovalController) OperationList() {
  853. br := new(models.BaseResponse).Init()
  854. defer func() {
  855. this.Data["json"] = br
  856. this.ServeJSON()
  857. }()
  858. sysUser := this.SysUser
  859. if sysUser == nil {
  860. br.Msg = "请登录"
  861. br.ErrMsg = "请登录,SysUser is Empty"
  862. br.Ret = 408
  863. return
  864. }
  865. reqSealId, _ := this.GetInt("SealId", 0)
  866. if reqSealId <= 0 {
  867. br.Msg = "用印申请编号获取失败!"
  868. br.ErrMsg = "用印申请编号获取失败!"
  869. return
  870. }
  871. list, err := seal.GetSealOperationRecordList(reqSealId)
  872. if err != nil {
  873. br.Msg = "获取列表失败!"
  874. br.ErrMsg = "获取列表失败!"
  875. return
  876. }
  877. br.Ret = 200
  878. br.Msg = "获取成功"
  879. br.Success = true
  880. br.Data = response.SealOperationListResp{
  881. List: list,
  882. }
  883. }
  884. // 关联公司列表
  885. // @Title 关联公司列表
  886. // @Description 关联公司列表
  887. // @Success 200 {object} response.SealApprovalListResp
  888. // @router /getAffiliatedCompany [get]
  889. func (this *SealApprovalController) AffiliatedCompanyList() {
  890. br := new(models.BaseResponse).Init()
  891. defer func() {
  892. this.Data["json"] = br
  893. this.ServeJSON()
  894. }()
  895. sysUser := this.SysUser
  896. if sysUser == nil {
  897. br.Msg = "请登录"
  898. br.ErrMsg = "请登录,SysUser is Empty"
  899. br.Ret = 408
  900. return
  901. }
  902. crmConfig, err := company.GetConfigDetailByCode("affiliated_company")
  903. if err != nil {
  904. br.Msg = "获取配置失败"
  905. br.ErrMsg = "获取配置失败"
  906. br.IsSendEmail = false
  907. return
  908. }
  909. list := strings.Split(crmConfig.ConfigValue, ",")
  910. br.Ret = 200
  911. br.Success = true
  912. br.Msg = "获取成功"
  913. br.Data = list
  914. }