seal.go 13 KB

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