2
3

suppliercertappend.go 29 KB

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