suppliercertappend.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. package oilsupplier
  2. import (
  3. msg2 "dashoo.cn/backend/api/business/msg"
  4. "dashoo.cn/backend/api/business/audithistory"
  5. "dashoo.cn/backend/api/business/auditsetting"
  6. "dashoo.cn/backend/api/business/oilsupplier/supplier"
  7. "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
  8. "dashoo.cn/backend/api/business/organize"
  9. "dashoo.cn/backend/api/business/register"
  10. "dashoo.cn/business2/parameter"
  11. "dashoo.cn/business2/userRole"
  12. "encoding/json"
  13. "fmt"
  14. "strconv"
  15. "strings"
  16. "time"
  17. "dashoo.cn/backend/api/business/oilsupplier/suppliercert"
  18. "dashoo.cn/backend/api/business/paymentinfo"
  19. "dashoo.cn/backend/api/business/workflow"
  20. "dashoo.cn/business2/permission"
  21. "dashoo.cn/backend/api/business/oilsupplier/suppliercertappend"
  22. "dashoo.cn/backend/api/business/oilsupplier/suppliercertappendsub"
  23. . "dashoo.cn/backend/api/controllers"
  24. "dashoo.cn/utils"
  25. "github.com/go-xorm/xorm"
  26. )
  27. type OilSupplierCertAppendController struct {
  28. BaseController
  29. }
  30. type AppShenHeModel struct {
  31. AnnualId int
  32. SuccessStatus int
  33. AuditorRemark string
  34. Auditer int
  35. MajorDept int
  36. }
  37. // @Title 获取列表
  38. // @Description 获取列表
  39. // @Success 200 {object} []suppliercertappend.OilSupplierCertAppend
  40. // @router /list [get]
  41. func (this *OilSupplierCertAppendController) GetList() {
  42. //获取分页信息
  43. page := this.GetPageInfoForm()
  44. where := " 1=1 "
  45. orderby := "b.Id"
  46. asc := false
  47. Order := this.GetString("Order")
  48. Prop := this.GetString("Prop")
  49. if Order != "" && Prop != "" {
  50. orderby = Prop
  51. if Order == "asc" {
  52. asc = true
  53. }
  54. }
  55. ApplyDate := this.GetString("ApplyDate")
  56. RecUnitId := this.GetString("RecUnitId")
  57. RecUnitName := this.GetString("RecUnitName")
  58. AppendType := this.GetString("AppendType")
  59. DenyReason := this.GetString("DenyReason")
  60. AuditDate := this.GetString("AuditDate")
  61. Remark := this.GetString("Remark")
  62. CreateOn := this.GetString("CreateOn")
  63. if ApplyDate != "" {
  64. where = where + " and b.ApplyDate like '%" + ApplyDate + "%'"
  65. }
  66. if RecUnitId != "" {
  67. where = where + " and b.RecUnitId like '%" + RecUnitId + "%'"
  68. }
  69. if RecUnitName != "" {
  70. where = where + " and b.RecUnitName like '%" + RecUnitName + "%'"
  71. }
  72. if AppendType != "" {
  73. where = where + " and b.AppendType like '%" + AppendType + "%'"
  74. }
  75. if DenyReason != "" {
  76. where = where + " and b.DenyReason like '%" + DenyReason + "%'"
  77. }
  78. if AuditDate != "" {
  79. where = where + " and b.AuditDate like '%" + AuditDate + "%'"
  80. }
  81. if Remark != "" {
  82. where = where + " and b.Remark like '%" + Remark + "%'"
  83. }
  84. if CreateOn != "" {
  85. dates := strings.Split(CreateOn, ",")
  86. if len(dates) == 2 {
  87. minDate := dates[0]
  88. maxDate := dates[1]
  89. where = where + " and b.CreateOn>='" + minDate + "' and b.CreateOn<='" + maxDate + "'"
  90. }
  91. }
  92. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  93. var registerUser register.OilCorporateInfo
  94. sql := " UserName='" + this.User.Username + "'"
  95. svc.GetEntity(&registerUser,sql)
  96. //企业用户必须加创建人条件
  97. if this.User.IsCompanyUser == 1 {
  98. where = where + " and (b.CreateUserId = '" + this.User.Id + "' or a.CommercialNo='"+registerUser.CommercialNo+"')"
  99. } else {
  100. //超级管理员和有查看所有数据权限的用户不加条件
  101. svcPerm := permission.GetPermissionService(utils.DBE)
  102. isauth := svcPerm.IsAuthorized(this.User.Id, "oil_supplier.append.AllRecord")
  103. if !svcPerm.IsAdmin(this.User.Id) && !isauth {
  104. where = where + " and (b.CreateUserId = '" + this.User.Id + "' or a.CommercialNo='"+registerUser.CommercialNo+"')"
  105. }
  106. }
  107. var list []suppliercertappend.OilSupplierCertAppend
  108. //total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
  109. total := svc.GetMyPagingEntitiesWithOrderBytbl(OilSupplierName, OilSupplierCertAppendName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  110. var datainfo DataInfo
  111. datainfo.Items = list
  112. datainfo.CurrentItemCount = total
  113. datainfo.PageIndex = page.CurrentPage
  114. datainfo.ItemsPerPage = page.Size
  115. this.Data["json"] = &datainfo
  116. this.ServeJSON()
  117. }
  118. // @Title 通过Id获取信息
  119. // @Description get user by token
  120. // @Success 200 {object} []suppliercertappend.OilSupplierCertAppend
  121. // @router /getEntityById/:id [get]
  122. func (this *OilSupplierCertAppendController) GetEntityById() {
  123. Id := this.Ctx.Input.Param(":id")
  124. var model suppliercertappend.OilSupplierCertAppend
  125. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  126. svc.GetEntityByIdBytbl(OilSupplierCertAppendName, Id, &model)
  127. this.Data["json"] = &model
  128. this.ServeJSON()
  129. }
  130. // @Title 获取公司信息
  131. // @Description 根据创建用户Id和增项类别号获取公司信息
  132. // @Success 200 {object} []suppliercertappend.OilSupplierCertAppend
  133. // @router /getsupplier [get]
  134. func (this *OilSupplierCertAppendController) GetSupplier() {
  135. SuppTypeCode := this.GetString("SuppTypeCode")
  136. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  137. where := "1=1 "
  138. if SuppTypeCode != "" {
  139. where = " WHERE b.Id is NOT NULL AND a.SupplierTypeCode = '" + SuppTypeCode + "' and a.InFlag='1'"
  140. }else {
  141. where = " WHERE b.Id is NOT NULL AND a.InFlag='1'"
  142. }
  143. var registerUser register.OilCorporateInfo
  144. sql := " UserName='" + this.User.Username + "'"
  145. svc.GetEntity(&registerUser,sql)
  146. //企业用户必须加创建人条件
  147. if this.User.IsCompanyUser == 1 {
  148. where = where + " and (b.CreateUserId = '" + this.User.Id + "' or b.CommercialNo='"+registerUser.CommercialNo+"')"
  149. //if this.User.IsCompanyUser == 1 {
  150. // where = where + " and b.CreateUserId = '" + this.User.Id + "'"
  151. }
  152. sqlStr := "SELECT b.Id AS SupplierId, a.Id AS SupplierCertId, b.SupplierName AS SupplierName FROM OilSupplierCert AS a LEFT JOIN OilSupplier AS b ON a.SupplierId = b.Id "
  153. sqlStr = sqlStr + where
  154. model, _ := svc.DBE.QueryString(sqlStr)
  155. this.Data["json"] = &model
  156. this.ServeJSON()
  157. }
  158. // @Title 添加
  159. // @Description 添加增项信息
  160. // @Success 200 {object} controllers.Request
  161. // @router /addappend [post]
  162. func (this *OilSupplierCertAppendController) AddAppend() {
  163. var errinfo DataEntryInfo
  164. var jsonblob = this.Ctx.Input.RequestBody
  165. var cermodel suppliercert.OilSupplierCert
  166. var model suppliercertappend.OilSupplierCertAppend
  167. json.Unmarshal(jsonblob, &model)
  168. where := " Id = "+ utils.ToStr(model.SupplierCertId)+ " and SupplierTypeCode = '"+ model.AppendType +"'"
  169. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  170. where_app := " SupplierCertId = "+ utils.ToStr(model.SupplierCertId)+ " and SupplierId = "+ utils.ToStr(model.SupplierId)+ " and AppendType = '"+ model.AppendType +"'"
  171. where_app += " and Status < 6"
  172. has := svc.GetEntityByWhere(OilSupplierCertAppendName, where_app, &model)
  173. if has {
  174. errinfo.Message = "已提交增项申请,审批通过后才可再提交申请!"
  175. errinfo.Code = -1
  176. errinfo.Info = model.Id
  177. this.Data["json"] = &errinfo
  178. this.ServeJSON()
  179. }
  180. svc.GetEntityByWhere(OilSupplierCertName, where, &cermodel)
  181. //if cermodel.Status != "8" {
  182. // errinfo.Message = "入库后才能提交增项!"
  183. // errinfo.Code = -1
  184. // this.Data["json"] = &errinfo
  185. // this.ServeJSON()
  186. // return
  187. //}
  188. //添加增项信息
  189. model.InStyle = cermodel.InStyle
  190. model.ApplyDate = time.Now() //申请日期
  191. model.CreateOn = time.Now()
  192. model.CreateBy = this.User.Realname
  193. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  194. _, err := svc.InsertEntityBytbl(OilSupplierCertAppendName, &model)
  195. //查询准入范围
  196. var certsublist []suppliercertsub.OilSupplierCertSub
  197. suwhere := " SupplierCertId = "+ utils.ToStr(model.SupplierCertId)+ " and SupplierTypeCode = "+ model.AppendType
  198. svc.GetEntitysByWhere(OilSupplierCertSubName, suwhere, &certsublist)
  199. if err == nil {
  200. errinfo.Message = "操作成功!"
  201. errinfo.Code = 0
  202. errinfo.Item = certsublist
  203. errinfo.Info = model.Id
  204. this.Data["json"] = &errinfo
  205. this.ServeJSON()
  206. } else {
  207. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  208. errinfo.Code = -1
  209. this.Data["json"] = &errinfo
  210. this.ServeJSON()
  211. }
  212. }
  213. // @Title 修改实体
  214. // @Description 修改实体
  215. // @Success 200 {object} controllers.Request
  216. // @router /update/:id [post]
  217. func (this *OilSupplierCertAppendController) UpdateEntity() {
  218. var errinfo ErrorInfo
  219. var model suppliercertappend.OilSupplierCertAppend
  220. id := this.Ctx.Input.Param(":id")
  221. if id == "" {
  222. errinfo.Message = "操作失败!请求信息不完整"
  223. errinfo.Code = -2
  224. this.Data["json"] = &errinfo
  225. this.ServeJSON()
  226. return
  227. }
  228. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  229. var jsonBlob = this.Ctx.Input.RequestBody
  230. json.Unmarshal(jsonBlob, &model)
  231. model.ApplyDate = time.Now() //更新申请日期
  232. model.ModifiedOn = time.Now()
  233. model.ModifiedBy = this.User.Realname
  234. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  235. cols := []string{
  236. "Id",
  237. "ApplyDate",
  238. "RecUnitFlag",
  239. "RecUnitId",
  240. "RecUnitName",
  241. "WorkRange",
  242. "Remark",
  243. "ModifiedOn",
  244. "ModifiedUserId",
  245. "ModifiedBy",
  246. }
  247. err := svc.UpdateEntityBytbl(OilSupplierCertAppendName, id, &model, cols)
  248. if err == nil {
  249. errinfo.Message = "修改成功!"
  250. errinfo.Code = 0
  251. this.Data["json"] = &errinfo
  252. this.ServeJSON()
  253. } else {
  254. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  255. errinfo.Code = -1
  256. this.Data["json"] = &errinfo
  257. this.ServeJSON()
  258. }
  259. }
  260. // @Title 删除
  261. // @Description 级联删除
  262. // @Success 200 {object} ErrorInfo
  263. // @Failure 403 :id 为空
  264. // @router /delete/:Id [delete]
  265. func (this *OilSupplierCertAppendController) DeleteEntity() {
  266. Id := this.Ctx.Input.Param(":Id")
  267. var errinfo ErrorInfo
  268. if Id == "" {
  269. errinfo.Message = "操作失败!请求信息不完整"
  270. errinfo.Code = -2
  271. this.Data["json"] = &errinfo
  272. this.ServeJSON()
  273. return
  274. }
  275. //定义session
  276. var session *xorm.Session
  277. session = utils.DBE.NewSession()
  278. svc := suppliercertappend.GetOilSupplierCertAppendSession(session)
  279. svcSub := suppliercertappendsub.GetOilSupplierCertAppendSubSession(session)
  280. //"session开始" 之前,首先定义 "session关闭"
  281. defer session.Close()
  282. err := session.Begin()
  283. where := "SupplierCertAppendId = " + Id
  284. //删除资质表信息
  285. var submodel []suppliercertsub.OilSupplierCertSub
  286. svc.GetEntitysByWhere(OilSupplierCertSubName,where,&submodel)
  287. if len(submodel) > 0 {
  288. filewhere := " SupplierId = "+ utils.ToStr(submodel[0].SupplierId) + " and SupType = 2 and SupplierTypeCode = '"+ submodel[0].SupplierTypeCode +"'"
  289. err = svcSub.DeleteEntityBytbl(OilSupplierFileName, filewhere)
  290. if err != nil {
  291. //回滚操作
  292. session.Rollback()
  293. }
  294. }
  295. //删除准入范围表信息
  296. err = svcSub.DeleteEntityBytbl(OilSupplierCertSubName, where)
  297. if err != nil {
  298. //回滚操作
  299. session.Rollback()
  300. }
  301. //最后删除主表信息
  302. var model suppliercertappend.OilSupplierCertAppend
  303. var entityempty suppliercertappend.OilSupplierCertAppend
  304. opdesc := "删除-" + Id
  305. err = svc.DeleteOperationAndWriteLogBytbl(OilSupplierCertAppendName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "增项信息")
  306. if err != nil {
  307. session.Rollback()
  308. }
  309. //提交操作
  310. err = session.Commit()
  311. if err == nil {
  312. errinfo.Message = "删除成功"
  313. errinfo.Code = 0
  314. this.Data["json"] = &errinfo
  315. this.ServeJSON()
  316. } else {
  317. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  318. errinfo.Code = -1
  319. this.Data["json"] = &errinfo
  320. this.ServeJSON()
  321. }
  322. }
  323. // @Title 获取列表
  324. // @Description get user by token
  325. // @Success 200 {object} []supplier.OilSupplierView
  326. // @router /mytasks [get]
  327. func (this *OilSupplierCertAppendController) GetMyTaskEntityList() {
  328. //获取分页信息
  329. page := this.GetPageInfoForm()
  330. where := " 1=1 "
  331. orderby := "Id"
  332. asc := false
  333. Order := this.GetString("Order")
  334. where = where + " and Status>0"
  335. Prop := this.GetString("Prop")
  336. if Order != "" && Prop != "" {
  337. orderby = Prop
  338. if Order == "asc" {
  339. asc = true
  340. }
  341. }
  342. ApplyDate := this.GetString("ApplyDate")
  343. RecUnitId := this.GetString("RecUnitId")
  344. RecUnitName := this.GetString("RecUnitName")
  345. AppendType := this.GetString("AppendType")
  346. DenyReason := this.GetString("DenyReason")
  347. AuditDate := this.GetString("AuditDate")
  348. Remark := this.GetString("Remark")
  349. CreateOn := this.GetString("CreateOn")
  350. if ApplyDate != "" {
  351. where = where + " and ApplyDate like '%" + ApplyDate + "%'"
  352. }
  353. if RecUnitId != "" {
  354. where = where + " and RecUnitId like '%" + RecUnitId + "%'"
  355. }
  356. if RecUnitName != "" {
  357. where = where + " and RecUnitName like '%" + RecUnitName + "%'"
  358. }
  359. if AppendType != "" {
  360. where = where + " and AppendType like '" + AppendType + "'"
  361. }
  362. if DenyReason != "" {
  363. where = where + " and DenyReason like '%" + DenyReason + "%'"
  364. }
  365. if AuditDate != "" {
  366. where = where + " and AuditDate like '%" + AuditDate + "%'"
  367. }
  368. if Remark != "" {
  369. where = where + " and Remark like '%" + Remark + "%'"
  370. }
  371. if CreateOn != "" {
  372. dates := strings.Split(CreateOn, ",")
  373. if len(dates) == 2 {
  374. minDate := dates[0]
  375. maxDate := dates[1]
  376. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  377. }
  378. }
  379. //找出待办任务
  380. actisvc := workflow.GetActivitiService(utils.DBE)
  381. var appendIdList string
  382. if actisvc.GetMyTasks(workflow.OIL_APPEND_APPLY, this.User.Id) != "" {
  383. appendIdList = actisvc.GetMyTasks(workflow.OIL_APPEND_APPLY, this.User.Id)
  384. appendIdList = appendIdList + ","
  385. }
  386. if actisvc.GetMyTasks(workflow.OIL_FIRST_APPEND_APPLY, this.User.Id) != "" {
  387. appendIdList = fmt.Sprintf("%s %s", appendIdList, actisvc.GetMyTasks(workflow.OIL_FIRST_APPEND_APPLY, this.User.Id))
  388. appendIdList = appendIdList + ","
  389. }
  390. if actisvc.GetMyTasks(workflow.OIL_SECOND_APPEND_APPLY, this.User.Id) != "" {
  391. appendIdList = fmt.Sprintf("%s %s", appendIdList, actisvc.GetMyTasks(workflow.OIL_SECOND_APPEND_APPLY, this.User.Id))
  392. appendIdList = appendIdList + ","
  393. }
  394. appendIdList = strings.Trim(appendIdList, ",")
  395. appendIdarr := strings.Split(appendIdList, ",")
  396. for i, item := range appendIdarr {
  397. idx := strings.Index(item,"-")
  398. if (idx >= 0 ) {
  399. appendIdarr[i] = strings.Split(item, "-")[0]
  400. }
  401. }
  402. appendIdList = strings.Join(appendIdarr, ",")
  403. var list []suppliercertappend.OilSupplierCertAppend
  404. var total int64 = 0
  405. if (appendIdList != "") {
  406. where += " and Id in (" + appendIdList + ")"
  407. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  408. total = svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
  409. }
  410. //根据部门查询待办任务
  411. var datainfo DataInfo
  412. datainfo.Items = list
  413. datainfo.CurrentItemCount = total
  414. datainfo.PageIndex = page.CurrentPage
  415. datainfo.ItemsPerPage = page.Size
  416. this.Data["json"] = &datainfo
  417. this.ServeJSON()
  418. }
  419. // @Title 提交审批
  420. // @Description 提交审批
  421. // @Success 200 {object} controllers.Request
  422. // @router /audit/:id [post]
  423. func (this *OilSupplierCertAppendController) AuditEntity() {
  424. certappendId := this.Ctx.Input.Param(":id")
  425. firstAudit := this.GetString("FirstAuditName")
  426. SecondAudit := this.GetString("SecondAudit")
  427. ThirdAudit := this.GetString("ThirdAudit")
  428. AuditRemark := this.GetString("AuditRemark")
  429. //取出审批列表
  430. certSrv := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  431. var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend
  432. certSrv.GetEntityById(certappendId, &supplierCertAppendEntity)
  433. var historworkflowid string
  434. historworkflowid = supplierCertAppendEntity.WorkFlowId
  435. var errinfo ErrorDataInfo
  436. defer func() { //finally处理失败的异常
  437. if err := recover(); err != nil {
  438. errinfo.Message = "提交失败," + err.(string)
  439. errinfo.Code = -1
  440. this.Data["json"] = &errinfo
  441. this.ServeJSON()
  442. } else {
  443. //返回正确结果
  444. errinfo.Message = "审核提交成功"
  445. errinfo.Code = 0
  446. this.Data["json"] = &errinfo
  447. this.ServeJSON()
  448. }
  449. }()
  450. var suppappend suppliercertappend.OilSupplierCertAppend
  451. //第二次提交先清空工作流
  452. if supplierCertAppendEntity.AuditIndex > 0 {
  453. suppappend.WorkFlowId = ""
  454. cols := []string{
  455. "WorkflowId",
  456. }
  457. certSrv.UpdateEntityByIdCols(certappendId, suppappend, cols)
  458. supplierCertAppendEntity.WorkFlowId = ""
  459. }
  460. svcActiviti := workflow.GetActivitiService(utils.DBE)
  461. processInstanceId := ""
  462. businessKey := ""
  463. if supplierCertAppendEntity.WorkFlowId == "0" || len(supplierCertAppendEntity.WorkFlowId) <= 0 {
  464. //启动工作流
  465. businessKey = certappendId + "-" + strconv.Itoa(supplierCertAppendEntity.AuditIndex)
  466. if this.User.IsCompanyUser == 1 {
  467. if supplierCertAppendEntity.InStyle == "2" {
  468. processInstanceId = svcActiviti.StartProcess(workflow.OIL_FIRST_ENUSER_APPEND_APPLY, businessKey, this.User.Id)
  469. } else if supplierCertAppendEntity.InStyle == "3" {
  470. processInstanceId = svcActiviti.StartProcess(workflow.OIL_SECOND_ENUSER_APPEND_APPLY, businessKey, this.User.Id)
  471. } else {
  472. processInstanceId = svcActiviti.StartProcess(workflow.OIL_ENUSER_APPEND_APPLY, businessKey, this.User.Id)
  473. }
  474. }else if this.User.IsCompanyUser == 0 {
  475. if supplierCertAppendEntity.InStyle == "2" {
  476. processInstanceId = svcActiviti.StartProcess(workflow.OIL_FIRST_APPEND_APPLY, businessKey, this.User.Id)
  477. }else if supplierCertAppendEntity.InStyle == "3" {
  478. processInstanceId = svcActiviti.StartProcess(workflow.OIL_SECOND_APPEND_APPLY, businessKey, this.User.Id)
  479. }else {
  480. processInstanceId = svcActiviti.StartProcess(workflow.OIL_APPEND_APPLY, businessKey, this.User.Id)
  481. }
  482. }
  483. }
  484. var ActiComplete workflow.ActiCompleteVM
  485. if this.User.IsCompanyUser == 1 {
  486. if supplierCertAppendEntity.InStyle == "2" {
  487. ActiComplete.ProcessKey = workflow.OIL_FIRST_ENUSER_APPEND_APPLY
  488. } else if supplierCertAppendEntity.InStyle == "3" {
  489. ActiComplete.ProcessKey = workflow.OIL_SECOND_ENUSER_APPEND_APPLY
  490. } else {
  491. ActiComplete.ProcessKey = workflow.OIL_ENUSER_APPEND_APPLY
  492. }
  493. }else if this.User.IsCompanyUser == 0 {
  494. if supplierCertAppendEntity.InStyle == "2" {
  495. ActiComplete.ProcessKey = workflow.OIL_FIRST_APPEND_APPLY
  496. }else if supplierCertAppendEntity.InStyle == "3" {
  497. ActiComplete.ProcessKey = workflow.OIL_SECOND_APPEND_APPLY
  498. }else{
  499. ActiComplete.ProcessKey = workflow.OIL_APPEND_APPLY
  500. }
  501. }
  502. ActiComplete.BusinessKey = businessKey
  503. ActiComplete.UserNames = firstAudit
  504. ActiComplete.UserId = this.User.Id
  505. ActiComplete.Result = "1"
  506. ActiComplete.Remarks = AuditRemark
  507. ActiComplete.CallbackUrl = ""
  508. receiveVal := svcActiviti.TaskComplete(ActiComplete)
  509. if receiveVal == "true" {
  510. if supplierCertAppendEntity.AuditIndex > 0 {
  511. // 审批历史
  512. var audithistoryentity audithistory.Base_AuditHistory
  513. audithistoryentity.EntityId, _ = strconv.Atoi(certappendId)
  514. audithistoryentity.WorkflowId = historworkflowid
  515. audithistoryentity.Process = workflow.OIL_APPEND_APPLY
  516. audithistoryentity.BusinessKey = businessKey
  517. audithistoryentity.Type = supplierCertAppendEntity.AppendType
  518. audithistoryentity.BackStep = supplierCertAppendEntity.Status
  519. audithistoryentity.Index = supplierCertAppendEntity.AuditIndex
  520. audithistoryentity.CreateOn = time.Now()
  521. audithistoryentity.CreateBy = this.User.Realname
  522. audithistoryentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  523. certSrv.InsertEntity(audithistoryentity)
  524. }
  525. errinfo.Message = "提交成功!"
  526. errinfo.Code = 0
  527. this.Data["json"] = &errinfo
  528. this.ServeJSON()
  529. } else {
  530. errinfo.Message = "工作流异常,请联系管理员!"
  531. errinfo.Code = -1
  532. this.Data["json"] = &errinfo
  533. this.ServeJSON()
  534. return
  535. }
  536. //记下workflowID(首次提交时才会记录,中间状态请忽略) 及审批状态
  537. var model suppliercertappend.OilSupplierCertAppend
  538. model.WorkFlowId = processInstanceId
  539. if this.User.IsCompanyUser == 1 {
  540. model.Status = suppliercert.FEN_TRIAL_STATUS //分办
  541. }else if this.User.IsCompanyUser == 0 {
  542. model.Status = suppliercert.FIRST_TRIAL_STATUS //二级单位初审
  543. }
  544. model.FirstAudit, _ = strconv.Atoi(firstAudit)
  545. model.SecondAudit, _ = strconv.Atoi(SecondAudit)
  546. model.ThirdAudit, _ = strconv.Atoi(ThirdAudit)
  547. model.AuditIndex = supplierCertAppendEntity.AuditIndex
  548. model.BusinessKey = businessKey
  549. model.ProcessKey = ActiComplete.ProcessKey
  550. cols := []string{
  551. "Id",
  552. "WorkFlowId",
  553. "Status",
  554. "FirstAudit",
  555. "SecondAudit",
  556. "ThirdAudit",
  557. "AuditIndex",
  558. "BusinessKey",
  559. "ProcessKey",
  560. }
  561. certSrv.UpdateEntityByIdCols(certappendId, model, cols)
  562. }
  563. // @Title 审批
  564. // @Description 审批
  565. // @Param body body suppliercert.OilSupplierCert
  566. // @Success 200 {object} controllers.Request
  567. // @router /auditEntityFir/:id [post]
  568. func (this *OilSupplierCertAppendController) AuditEntityFir() {
  569. appendId := this.Ctx.Input.Param(":id")
  570. firstAudit := this.GetString("FirstAuditName")
  571. secondAudit := this.GetString("SecondAudit")
  572. thirdAudit := this.GetString("ThirdAudit")
  573. //取出审批列表
  574. //certSrv := suppliercert.GetOilSupplierCertService(utils.DBE)
  575. svc := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
  576. var supplierCertAppendEntity suppliercertappend.OilSupplierCertAppend
  577. svc.GetEntityById(appendId, &supplierCertAppendEntity)
  578. var supplierEntity supplier.OilSupplier
  579. wheresup := "Id=" + strconv.Itoa(supplierCertAppendEntity.SupplierId)
  580. svc.GetEntity(&supplierEntity, wheresup)
  581. var jsonblob = this.Ctx.Input.RequestBody
  582. var dataother AppShenHeModel
  583. json.Unmarshal(jsonblob, &dataother)
  584. var errinfo ErrorDataInfo
  585. defer func() { //finally处理失败的异常
  586. if err := recover(); err != nil {
  587. errinfo.Message = "提交失败," + err.(string)
  588. errinfo.Code = -1
  589. this.Data["json"] = &errinfo
  590. this.ServeJSON()
  591. } else {
  592. //返回正确结果
  593. errinfo.Message = "审核提交成功"
  594. errinfo.Code = 0
  595. this.Data["json"] = &errinfo
  596. this.ServeJSON()
  597. }
  598. }()
  599. step := 2
  600. status := ""
  601. backstatus := "0"
  602. var userIds string
  603. if supplierCertAppendEntity.Status == suppliercert.FEN_TRIAL_STATUS {
  604. userIds = firstAudit
  605. status = suppliercert.FIRST_TRIAL_STATUS
  606. step = 2
  607. supplierCertAppendEntity.FirstAudit, _ = strconv.Atoi(firstAudit)
  608. supplierCertAppendEntity.SecondAudit,_ = strconv.Atoi(secondAudit)
  609. supplierCertAppendEntity.ThirdAudit,_ = strconv.Atoi(thirdAudit)
  610. cols := []string{
  611. "Id",
  612. "FirstAudit",
  613. "SecondAudit",
  614. "ThirdAudit",
  615. }
  616. svc.UpdateEntityByIdCols(appendId, supplierCertAppendEntity, cols)
  617. }
  618. if supplierCertAppendEntity.Status == suppliercert.FIRST_TRIAL_STATUS {
  619. userIds = utils.ToStr(supplierCertAppendEntity.SecondAudit)
  620. status = suppliercert.SECOND_TRIAL_STATUS
  621. step = 2
  622. backstatus = suppliercert.NOPASS_STATUS
  623. } else if supplierCertAppendEntity.Status == suppliercert.SECOND_TRIAL_STATUS {
  624. svc := organize.GetOrganizeService(utils.DBE)
  625. unitId := svc.GetMyUnitDepartmentId(strconv.Itoa(supplierCertAppendEntity.ThirdAudit))
  626. var userlist []userRole.Base_User
  627. var setting auditsetting.Base_OilAuditSetting
  628. usvc := userRole.GetUserService(utils.DBE)
  629. if supplierCertAppendEntity.InStyle == "2" {
  630. status = suppliercert.CENT_AUDIT_STATUS
  631. where := "AuditStepCode='" + workflow.PROF_REGULATION + "'"
  632. usvc.GetEntity(&setting, where)
  633. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  634. topid := paramSvc.GetBaseparameterMessage("", "paramset", "CENT_AUDIT")
  635. ids := usvc.GetUserIdsByRoleId(strconv.Itoa(setting.RoleId))
  636. tempstr := strings.Join(ids, ",")
  637. uids := strings.Replace(tempstr, "uid_", "", -1)
  638. uids = strings.Trim(uids, ",")
  639. if uids != "" {
  640. where := "Id in (" + uids + ")" + " and UnitId=" + topid
  641. usvc.GetEntities(&userlist, where)
  642. }
  643. } else {
  644. status = suppliercert.THIRD_TRIAL_STATUS
  645. where := "AuditStepCode='" + workflow.PROF_RECE + "'"
  646. svc.GetEntity(&setting, where)
  647. ids := usvc.GetUserIdsByRoleId(strconv.Itoa(setting.RoleId))
  648. tempstr := strings.Join(ids, ",")
  649. uids := strings.Replace(tempstr, "uid_", "", -1)
  650. uids = strings.Trim(uids, ",")
  651. if uids != "" {
  652. where := "Id in (" + uids + ")" + " and UnitId=" + unitId
  653. svc.GetEntities(&userlist, where)
  654. }
  655. }
  656. for _, tmpUser := range userlist {
  657. userIds += strconv.Itoa(tmpUser.Id) + "," //strconv.FormatInt(tmpUser.Id, 10) + ","
  658. }
  659. userIds = strings.Trim(userIds, ",")
  660. step = 2
  661. backstatus = suppliercert.NO_SECOND_TRIAL_STATUS
  662. } else if supplierCertAppendEntity.Status == suppliercert.THIRD_TRIAL_STATUS {
  663. userIds = utils.ToStr(dataother.Auditer)
  664. status = suppliercert.PROF_AUDIT_STATUS
  665. step = 2
  666. backstatus = suppliercert.NO_THIRD_TRIAL_STATUS
  667. } else if supplierCertAppendEntity.Status == suppliercert.PROF_AUDIT_STATUS {
  668. if supplierCertAppendEntity.InStyle == "3" {
  669. status = suppliercert.PAYING_AUDIT_STATUS
  670. step = 3
  671. backstatus = suppliercert.NO_CENT_AUDIT_STATUS
  672. } else {
  673. status = suppliercert.CENT_AUDIT_STATUS
  674. step = 2
  675. backstatus = suppliercert.NO_PROF_AUDIT_STATUS
  676. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  677. topid := paramSvc.GetBaseparameterMessage("", "paramset", "CENT_AUDIT")
  678. var userlist []userRole.Base_User
  679. var setting auditsetting.Base_OilAuditSetting
  680. usvc := userRole.GetUserService(utils.DBE)
  681. where := "AuditStepCode='" + workflow.PROF_REGULATION + "'"
  682. usvc.GetEntity(&setting, where)
  683. ids := usvc.GetUserIdsByRoleId(strconv.Itoa(setting.RoleId))
  684. tempstr := strings.Join(ids, ",")
  685. uids := strings.Replace(tempstr, "uid_", "", -1)
  686. uids = strings.Trim(uids, ",")
  687. if uids != "" {
  688. where := "Id in (" + uids + ")" + " and UnitId=" + topid
  689. usvc.GetEntities(&userlist, where)
  690. }
  691. for _, tmpUser := range userlist {
  692. userIds += strconv.Itoa(tmpUser.Id) + ","
  693. }
  694. userIds = strings.Trim(userIds, ",")
  695. }
  696. } else if supplierCertAppendEntity.Status == suppliercert.CENT_AUDIT_STATUS {
  697. userIds = utils.ToStr(dataother.Auditer)
  698. status = suppliercert.PAYING_AUDIT_STATUS
  699. step = 3
  700. backstatus = suppliercert.NO_CENT_AUDIT_STATUS
  701. }
  702. svcActiviti := workflow.GetActivitiService(utils.DBE)
  703. var ActiComplete workflow.ActiCompleteVM
  704. ActiComplete.ProcessKey = supplierCertAppendEntity.ProcessKey
  705. ActiComplete.BusinessKey = supplierCertAppendEntity.BusinessKey
  706. ActiComplete.UserNames = userIds
  707. ActiComplete.UserId = this.User.Id
  708. ActiComplete.Remarks = dataother.AuditorRemark
  709. ActiComplete.CallbackUrl = ""
  710. if dataother.SuccessStatus == 1 {
  711. ActiComplete.Result = "1"
  712. receiveVal := svcActiviti.TaskComplete(ActiComplete)
  713. if receiveVal == "true" {
  714. if supplierCertAppendEntity.Status == "5" {
  715. if supplierCertAppendEntity.InStyle == "1" {
  716. paysvc := paymentinfo.GetPaymentService(utils.DBE)
  717. var Amount float64
  718. if supplierCertAppendEntity.AppendType == "01" {
  719. Amount = 6000
  720. } else if supplierCertAppendEntity.AppendType == "02" {
  721. Amount = 7000
  722. } else if supplierCertAppendEntity.AppendType == "03" {
  723. Amount = 8000
  724. }
  725. var payinfo paymentinfo.OilPaymentInfo
  726. payinfo.SupplierId = supplierCertAppendEntity.SupplierId
  727. payinfo.SupplierCertId = supplierCertAppendEntity.SupplierCertId
  728. payinfo.USCCode = supplierEntity.CommercialNo
  729. payinfo.SupplierName = supplierEntity.SupplierName
  730. payinfo.PayType = "3"
  731. payinfo.IsPay = "1"
  732. payinfo.Amount = strconv.FormatFloat(Amount,'E',-1,64)
  733. payinfo.CreateUserId = supplierCertAppendEntity.CreateUserId
  734. payinfo.CreateBy = supplierCertAppendEntity.CreateBy
  735. payinfo.CreateOn = time.Now()
  736. paysvc.InsertEntity(&payinfo)
  737. //发短信
  738. toMobile := supplierEntity.Mobile
  739. bFlag:=""
  740. if supplierCertAppendEntity.AppendType == "01"{
  741. bFlag="物资类"
  742. }else if supplierCertAppendEntity.AppendType == "02"{
  743. bFlag="基建类"
  744. }else{
  745. bFlag="技术服务类"
  746. }
  747. msg:= "您的"+ bFlag + "增项审核通过,请及时确认缴费信息!"
  748. msgService := msg2.GetMsgService(utils.DBE)
  749. msgService.HandleMsg(toMobile,msg,"4-1",supplierCertAppendEntity.CreateBy,supplierEntity.ContactName,strconv.Itoa(supplierCertAppendEntity.CreateUserId))
  750. //paysvc.AddPaymentinfo(supplierCertAppendEntity.SupplierId, supplierCertAppendEntity.Id, Amount, "3")
  751. }
  752. }
  753. supplierCertAppendEntity.Status = status
  754. supplierCertAppendEntity.Step = step
  755. cols := []string{
  756. "Status",
  757. "Step",
  758. }
  759. svc.UpdateEntityByIdCols(appendId, supplierCertAppendEntity, cols)
  760. errinfo.Message = "提交成功!"
  761. errinfo.Code = 0
  762. this.Data["json"] = &errinfo
  763. this.ServeJSON()
  764. } else {
  765. errinfo.Message = "工作流异常,请联系管理员!"
  766. errinfo.Code = -1
  767. this.Data["json"] = &errinfo
  768. this.ServeJSON()
  769. return
  770. }
  771. } else {
  772. ActiComplete.Result = "0"
  773. receiveVal := svcActiviti.TaskComplete(ActiComplete)
  774. if receiveVal == "true" {
  775. if supplierCertAppendEntity.Status == "5" {
  776. supplierCertAppendEntity.Status = backstatus
  777. supplierCertAppendEntity.Step = step
  778. supplierCertAppendEntity.AuditIndex = supplierCertAppendEntity.AuditIndex + 1
  779. }else {
  780. supplierCertAppendEntity.Status = "-1"
  781. supplierCertAppendEntity.Status = "0"
  782. supplierCertAppendEntity.Step = 1
  783. supplierCertAppendEntity.AuditIndex = supplierCertAppendEntity.AuditIndex + 1
  784. }
  785. cols := []string{
  786. "Status",
  787. "Step",
  788. "AuditIndex",
  789. }
  790. _,err := svc.UpdateEntityByIdCols(appendId, supplierCertAppendEntity, cols)
  791. if err == nil {
  792. errinfo.Message = "提交成功!"
  793. errinfo.Code = 0
  794. this.Data["json"] = &errinfo
  795. this.ServeJSON()
  796. }else {
  797. errinfo.Message = "提交失败!"
  798. errinfo.Code = -1
  799. this.Data["json"] = &errinfo
  800. this.ServeJSON()
  801. }
  802. } else {
  803. errinfo.Message = "工作流异常,请联系管理员!"
  804. errinfo.Code = -1
  805. this.Data["json"] = &errinfo
  806. this.ServeJSON()
  807. return
  808. }
  809. }
  810. }