seal.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. sealReq "hongze/hongze_mobile_admin/models/request/seal"
  6. sealResp "hongze/hongze_mobile_admin/models/response/seal"
  7. "hongze/hongze_mobile_admin/models/tables/company"
  8. "hongze/hongze_mobile_admin/models/tables/seal"
  9. contractService "hongze/hongze_mobile_admin/services/contract"
  10. sealService "hongze/hongze_mobile_admin/services/seal"
  11. "hongze/hongze_mobile_admin/utils"
  12. "path"
  13. "strconv"
  14. )
  15. //SealCommon
  16. //用印模块
  17. type SealCommon struct {
  18. BaseAuth
  19. }
  20. //Add
  21. // @Title 新增用印
  22. // @Description 新增用印接口
  23. // @Param request body seal.AddReq true "type json string"
  24. // @Success Ret=200 新增用印成功
  25. // @router /add [post]
  26. func (c *SealCommon) Add() {
  27. var req sealReq.AddReq
  28. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  29. if err != nil {
  30. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  31. return
  32. }
  33. // 参数校验
  34. if req.Use == "" {
  35. c.FailWithMessage("用印用途不能为空", "用印用途不能为空")
  36. return
  37. }
  38. if req.CompanyName == "" {
  39. c.FailWithMessage("客户名称不能为空", "客户名称不能为空")
  40. return
  41. }
  42. if req.CreditCode == "" {
  43. c.FailWithMessage("社会统一信用代码不能为空", "社会统一信用代码不能为空")
  44. return
  45. }
  46. if req.ServiceType == "" {
  47. c.FailWithMessage("合同类型不能为空", "合同类型不能为空")
  48. return
  49. }
  50. if req.SealType == "" {
  51. c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
  52. return
  53. }
  54. if len(req.FileUrls) == 0 {
  55. c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
  56. return
  57. }
  58. sealInfo, err := sealService.AddSeal(c.AdminWx.AdminId, req.ContractId, req.FileNum, c.AdminWx.RealName, req.Use, req.UseCompanyName, req.CompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls)
  59. if err != nil {
  60. c.FailWithMessage("用印添加失败", err.Error())
  61. return
  62. }
  63. err = sealService.Apply(sealInfo)
  64. if err != nil {
  65. c.FailWithMessage("发起用印审批失败", "发起用印审批失败,Err:"+err.Error())
  66. return
  67. }
  68. c.OkDetailed(sealResp.AddSealResp{
  69. SealId: sealInfo.SealId,
  70. }, "发起用印审批成功")
  71. }
  72. //Edit
  73. // @Title 编辑用印
  74. // @Description 编辑用印接口
  75. // @Param request body seal.EditReq true "type json string"
  76. // @Success 200 {object} seal.AddSealResp
  77. // @router /edit [post]
  78. func (c *SealCommon) Edit() {
  79. var req sealReq.EditReq
  80. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  81. if err != nil {
  82. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  83. return
  84. }
  85. // 参数校验
  86. if req.SealId <= 0 {
  87. c.FailWithMessage("用印编号不能为空", "用印编号不能为空")
  88. return
  89. }
  90. if req.Use == "" {
  91. c.FailWithMessage("用印用途不能为空", "用印用途不能为空")
  92. return
  93. }
  94. if req.CompanyName == "" {
  95. c.FailWithMessage("客户名称不能为空", "客户名称不能为空")
  96. return
  97. }
  98. if req.CreditCode == "" {
  99. c.FailWithMessage("社会统一信用代码不能为空", "社会统一信用代码不能为空")
  100. return
  101. }
  102. if req.ServiceType == "" {
  103. c.FailWithMessage("合同类型不能为空", "合同类型不能为空")
  104. return
  105. }
  106. if req.SealType == "" {
  107. c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
  108. return
  109. }
  110. if len(req.FileUrls) == 0 {
  111. c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
  112. return
  113. }
  114. sealInfo, err := sealService.Edit(req.SealId, c.AdminWx.AdminId, req.ContractId, req.FileNum, req.Use, req.CompanyName, req.UseCompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls, c.AdminWx.RealName)
  115. if err != nil {
  116. c.FailWithMessage("修改合同失败!", "修改合同失败,Err:"+err.Error())
  117. return
  118. }
  119. tmpErr := sealService.Apply(sealInfo)
  120. if tmpErr != nil {
  121. c.FailWithMessage("发起重申失败!", "发起重申失败,Err:"+tmpErr.Error())
  122. return
  123. }
  124. c.OkDetailed(sealResp.AddSealResp{
  125. SealId: sealInfo.SealId,
  126. }, "发起重申成功")
  127. }
  128. //CheckEdit
  129. // @Title 审批者编辑用印
  130. // @Description 审批者编辑用印接口
  131. // @Param request body seal.CheckEditReq true "type json string"
  132. // @Success 200 {object} seal.AddSealResp
  133. // @router /check_edit [post]
  134. func (c *SealCommon) CheckEdit() {
  135. var req sealReq.CheckEditReq
  136. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  137. if err != nil {
  138. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  139. return
  140. }
  141. // 参数校验
  142. sealId := req.SealId
  143. if sealId <= 0 {
  144. c.FailWithMessage("用印编号不能为空", "用印编号不能为空")
  145. return
  146. }
  147. if req.Use == "" {
  148. c.FailWithMessage("用印用途不能为空", "用印用途不能为空")
  149. return
  150. }
  151. if req.SealType == "" {
  152. c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
  153. return
  154. }
  155. if len(req.FileUrls) == 0 {
  156. c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
  157. return
  158. }
  159. //数据校验(校验是否具有审批权限)
  160. sealInfo, approvalInfo, approvalRecord, err := sealService.CheckApproveAuth(sealId, c.AdminWx)
  161. //合规修改
  162. err = sealService.CheckEdit(sealInfo, approvalInfo, approvalRecord, req.FileNum, req.FileUrls, req.Use, req.SealType, req.Remark, c.AdminWx)
  163. if err != nil {
  164. c.FailWithMessage("修改合同失败!", "修改合同失败,Err:"+err.Error())
  165. return
  166. }
  167. c.OkDetailed(sealResp.AddSealResp{
  168. SealId: sealInfo.SealId,
  169. }, "修改合同成功")
  170. }
  171. // List
  172. // @Title 用印列表
  173. // @Description 用印列表接口
  174. // @Param Status query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废','已签回'"
  175. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  176. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  177. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  178. // @Param AdminId query string false "选择的用户id"
  179. // @Param Keyword query string false "搜索关键字"
  180. // @Param KeywordEq query string false "搜索关键字(全匹配搜索)"
  181. // @Success 200 {object} contract.ContractListResp
  182. // @router /list [get]
  183. func (c *SealCommon) List() {
  184. //合同类型、产品类型、合同状态、更新时间、所选销售
  185. //关键字:合同编号、客户名称,社会信用码
  186. status := c.GetString("Status")
  187. productId, _ := c.GetInt("ProductId")
  188. modifyStartTime := c.GetString("ModifyStartTime")
  189. modifyEndTime := c.GetString("ModifyEndTime")
  190. adminIds := c.GetString("AdminId")
  191. keyword := c.GetString("Keyword")
  192. keywordEq := c.GetString("KeywordEq")
  193. condition := ""
  194. pars := make([]interface{}, 0)
  195. //合同类型、、更新时间、所选销售
  196. //关键字:合同编号、客户名称,社会信用码
  197. //合同状态
  198. if status != "" {
  199. condition += ` AND status = ? `
  200. pars = append(pars, status)
  201. }
  202. //产品类型
  203. if productId > 0 {
  204. condition += ` AND product_id = ? `
  205. pars = append(pars, productId)
  206. }
  207. //所选销售
  208. if adminIds != "" {
  209. condition += ` AND user_id IN (` + adminIds + `) `
  210. } else {
  211. condition += ` AND user_id =?`
  212. pars = append(pars, c.AdminWx.AdminId)
  213. }
  214. //更新开始时间
  215. if modifyStartTime != "" {
  216. condition += ` AND modify_time >= ? `
  217. pars = append(pars, modifyStartTime)
  218. }
  219. //更新结束时间
  220. if modifyEndTime != "" {
  221. condition += ` AND modify_time <= ? `
  222. pars = append(pars, modifyEndTime)
  223. }
  224. //关键字
  225. if keyword != "" {
  226. condition += ` AND (code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR credit_code LIKE '%` + keyword + `%' ) `
  227. }
  228. //关键字(全等)
  229. if keywordEq != "" {
  230. condition += ` AND (c.use_company_name =? OR c.company_name =?) `
  231. pars = append(pars, keywordEq, keywordEq)
  232. }
  233. pageSize, _ := c.GetInt("PageSize")
  234. currentIndex, _ := c.GetInt("CurrentIndex")
  235. var startSize int
  236. if pageSize <= 0 {
  237. pageSize = utils.PageSize20
  238. }
  239. if currentIndex <= 0 {
  240. currentIndex = 1
  241. }
  242. startSize = paging.StartIndex(currentIndex, pageSize)
  243. total, err := seal.GetListCount(condition, pars)
  244. if err != nil {
  245. c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
  246. return
  247. }
  248. list, err := seal.GetList(condition, pars, startSize, pageSize)
  249. if err != nil {
  250. c.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
  251. return
  252. }
  253. page := paging.GetPaging(currentIndex, pageSize, total)
  254. c.OkDetailed(sealResp.RespSealList{
  255. List: list,
  256. Paging: page,
  257. }, "获取成功")
  258. }
  259. //Detail
  260. // @Title 获取用印详情
  261. // @Description 获取用印详情接口
  262. // @Param SealId query int true "用印id"
  263. // @Success 200 {object} seal.SealDetailResp
  264. // @router /detail [get]
  265. func (c *SealCommon) Detail() {
  266. //合同类型、产品类型、合同状态、更新时间、所选销售
  267. //关键字:合同编号、客户名称,社会信用码
  268. sealId, _ := c.GetInt("SealId")
  269. //用印id
  270. if sealId <= 0 {
  271. c.FailWithMessage("用印id必传!", "用印id必传!")
  272. return
  273. }
  274. sealInfo, flowNodeListResp, opButton, err := sealService.GetSealDetailBySealId(sealId, c.AdminWx)
  275. if err != nil {
  276. c.FailWithMessage("获取详情失败", "获取详情失败,Err:"+err.Error())
  277. return
  278. }
  279. resp := sealResp.SealDetailResp{
  280. SealDetail: sealInfo,
  281. FlowNodeList: flowNodeListResp,
  282. OpButton: opButton,
  283. }
  284. c.OkDetailed(resp, "获取成功")
  285. }
  286. //Invalid
  287. // @Title 作废合同
  288. // @Description 作废合同接口
  289. // @Param request body seal.InvalidReq true "type json string"
  290. // @Success Ret=200 作废成功
  291. // @router /invalid [post]
  292. func (c *SealCommon) Invalid() {
  293. var req sealReq.InvalidReq
  294. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  295. if err != nil {
  296. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  297. return
  298. }
  299. //用印id
  300. if req.SealId <= 0 {
  301. c.FailWithMessage("用印id必传!", "用印id必传!")
  302. return
  303. }
  304. err = sealService.Invalid(req.SealId, c.AdminWx, req.IsInvalidContract)
  305. if err != nil {
  306. c.FailWithMessage("作废用印失败!", "作废用印失败,Err:"+err.Error())
  307. return
  308. }
  309. c.OkWithMessage("作废成功")
  310. return
  311. }
  312. // UploadCheckBackFile
  313. // @Title 上传签回附件
  314. // @Description 上传签回附件接口
  315. // @Param request body seal.UploadCheckBackFileReq true "type json string"
  316. // @Success Ret=200 上传成功
  317. // @router /upload_check_back_file [post]
  318. func (c *SealCommon) UploadCheckBackFile() {
  319. //var req sealReq.UploadCheckBackFileReq
  320. //err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  321. //if err != nil {
  322. // c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  323. // return
  324. //}
  325. ////用印编号
  326. //if req.SealId <= 0 {
  327. // c.FailWithMessage("请传入用印编号!", "请传入用印编号")
  328. // return
  329. //}
  330. //
  331. //if req.FileUrl == "" {
  332. // c.FailWithMessage("请先上传附件!", "请先上传附件")
  333. // return
  334. //}
  335. sealIdStr := c.Ctx.Request.Form.Get("SealId")
  336. if sealIdStr == "" {
  337. c.FailWithMessage("用印ID必传!", "用印ID必传")
  338. return
  339. }
  340. sealId, err := strconv.Atoi(sealIdStr)
  341. if err != nil {
  342. c.FailWithMessage("用印ID异常!", "用印ID必传")
  343. return
  344. }
  345. //合同编号
  346. if sealId <= 0 {
  347. c.FailWithMessage("请传入用印编号", "请传入用印编号")
  348. return
  349. }
  350. fileMulti, h, err := c.GetFile("file")
  351. if err != nil {
  352. c.FailWithMessage("获取资源信息失败", "获取资源信息失败,Err:"+err.Error())
  353. return
  354. }
  355. ext := path.Ext(h.Filename)
  356. //sealInfo, err := sealService.UploadCheckBackFile(req.SealId, req.FileUrl, c.AdminWx)
  357. sealInfo, err := sealService.UploadCheckBackFileByFile(sealId, ext, fileMulti, c.AdminWx)
  358. if err != nil {
  359. c.FailWithMessage("更新签回附件失败!", "更新签回附件失败,Err:"+err.Error())
  360. return
  361. }
  362. //如果是系统合同,那么需要去更新系统的签回附件
  363. if sealInfo.ContractId > 0 {
  364. _ = contractService.UploadCheckBackFile(sealInfo.ContractId, sealInfo.CheckBackFileUrl, c.AdminWx)
  365. }
  366. c.OkWithMessage("上传成功")
  367. }
  368. //CompanyList
  369. // @Title 根据客户名称获取已存在系统中客户名称列表
  370. // @Description 获取合同详情接口
  371. // @Param Keyword query string true "关键字:客户名称、组织社会信用码"
  372. // @Success 200 {object} []string
  373. // @router /company_list [get]
  374. func (c *SealCommon) CompanyList() {
  375. sysUser := c.AdminWx
  376. keyword := c.GetString("Keyword")
  377. //合同id
  378. if keyword == "" {
  379. c.FailWithMessage("搜索关键字必传!", "搜索关键字必传!")
  380. return
  381. }
  382. companyNameList := make([]string, 0)
  383. childCondition := ""
  384. condition := ""
  385. childPars := make([]interface{}, 0)
  386. pars := make([]interface{}, 0)
  387. //归属
  388. condition += ` AND (c.user_id = ? or (d.approve_user_id = ? and d.node_id <= a.curr_node_id))`
  389. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  390. condition += ` AND (c.company_name like "%` + keyword + `%" or c.credit_code like "%` + keyword + `%")`
  391. list, err := seal.GetCompanyNameListV2(childCondition, condition, childPars, pars)
  392. if err != nil {
  393. c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  394. return
  395. }
  396. for _, v := range list {
  397. companyNameList = append(companyNameList, v.CompanyName)
  398. }
  399. c.OkDetailed(companyNameList, "获取成功")
  400. }
  401. // CompanyNameList
  402. // @Title 根据客户名称关键词获取系统中的客户名称列表
  403. // @Description 获取客户名称列表
  404. // @Param Keyword query string true "客户名称关键词"
  405. // @Param PageSize query int true "每页数据量"
  406. // @Param CurrentIndex query int true "页码"
  407. // @Success 200 {object} []company.CompanyNameList
  408. // @router /company_name_list [get]
  409. func (c *SealCommon) CompanyNameList() {
  410. keyword := c.GetString("Keyword")
  411. pageSize, _ := c.GetInt("PageSize")
  412. currentIndex, _ := c.GetInt("CurrentIndex")
  413. if keyword == "" {
  414. c.FailWithMessage("关键词不能为空", "关键词不能为空")
  415. return
  416. }
  417. var startSize int
  418. if pageSize <= 0 {
  419. pageSize = utils.PageSize20
  420. }
  421. if currentIndex <= 0 {
  422. currentIndex = 1
  423. }
  424. startSize = paging.StartIndex(currentIndex, pageSize)
  425. keyword = "%" + keyword + "%"
  426. condition := " AND company_name LIKE ? "
  427. pars := make([]interface{}, 0)
  428. pars = append(pars, keyword)
  429. list, err := company.GetCompanyNameList(condition, pars, startSize, pageSize)
  430. if err != nil {
  431. c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error())
  432. return
  433. }
  434. c.OkDetailed(list, "获取成功")
  435. }