2
3

suppliercertappend.go 33 KB

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