suppliercert.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. package oilsupplier
  2. import (
  3. "encoding/json"
  4. "strings"
  5. "time"
  6. "dashoo.cn/backend/api/business/workflow"
  7. "dashoo.cn/backend/api/business/baseUser"
  8. "dashoo.cn/backend/api/business/oilsupplier/suppliercert"
  9. . "dashoo.cn/backend/api/controllers"
  10. "dashoo.cn/business2/userRole"
  11. "dashoo.cn/utils"
  12. )
  13. type OilSupplierCertController struct {
  14. BaseController
  15. }
  16. // @Title 获取列表
  17. // @Description get user by token
  18. // @Success 200 {object} []suppliercert.OilSupplierCert
  19. // @router /list [get]
  20. func (this *OilSupplierCertController) GetEntityList() {
  21. //获取分页信息
  22. page := this.GetPageInfoForm()
  23. where := " 1=1 "
  24. orderby := "Id"
  25. asc := false
  26. Order := this.GetString("Order")
  27. Prop := this.GetString("Prop")
  28. if Order != "" && Prop != "" {
  29. orderby = Prop
  30. if Order == "asc" {
  31. asc = true
  32. }
  33. }
  34. Id := this.GetString("Id")
  35. SupplierId := this.GetString("SupplierId")
  36. AccessCardNo := this.GetString("AccessCardNo")
  37. SupplierTypeCode := this.GetString("SupplierTypeCode")
  38. SupplierTypeName := this.GetString("SupplierTypeName")
  39. RecUnitReason := this.GetString("RecUnitReason")
  40. RecUnitPerson := this.GetString("RecUnitPerson")
  41. RecDate := this.GetString("RecDate")
  42. RecUnitId := this.GetString("RecUnitId")
  43. RecUnitName := this.GetString("RecUnitName")
  44. StatusA := this.GetString("StatusA")
  45. BackReason := this.GetString("BackReason")
  46. InFlag := this.GetString("InFlag")
  47. EffectStartTime := this.GetString("EffectStartTime")
  48. EffectEndTime := this.GetString("EffectEndTime")
  49. AuditProcessNote := this.GetString("AuditProcessNote")
  50. AuditDate := this.GetString("AuditDate")
  51. PayNotice := this.GetString("PayNotice")
  52. SupplierStatus := this.GetString("SupplierStatus")
  53. MgrType := this.GetString("MgrType")
  54. Type := this.GetString("Type")
  55. MgrUnit := this.GetString("MgrUnit")
  56. AddinTime := this.GetString("AddinTime")
  57. EffectTime := this.GetString("EffectTime")
  58. ApplyTime := this.GetString("ApplyTime")
  59. SupplierNo := this.GetString("SupplierNo")
  60. MDMFlag := this.GetString("MDMFlag")
  61. InternalFlag := this.GetString("InternalFlag")
  62. ImportFlag := this.GetString("ImportFlag")
  63. OutsideFlog := this.GetString("OutsideFlog")
  64. Remark := this.GetString("Remark")
  65. IsDelete := this.GetString("IsDelete")
  66. CreateOn := this.GetString("CreateOn")
  67. CreateUserId := this.GetString("CreateUserId")
  68. CreateBy := this.GetString("CreateBy")
  69. ModifiedOn := this.GetString("ModifiedOn")
  70. ModifiedUserId := this.GetString("ModifiedUserId")
  71. ModifiedBy := this.GetString("ModifiedBy")
  72. if Id != "" {
  73. where = where + " and Id like '%" + Id + "%'"
  74. }
  75. if SupplierId != "" {
  76. where = where + " and SupplierId like '%" + SupplierId + "%'"
  77. }
  78. if AccessCardNo != "" {
  79. where = where + " and AccessCardNo like '%" + AccessCardNo + "%'"
  80. }
  81. if SupplierTypeCode != "" {
  82. where = where + " and SupplierTypeCode like '%" + SupplierTypeCode + "%'"
  83. }
  84. if SupplierTypeName != "" {
  85. where = where + " and SupplierTypeName like '%" + SupplierTypeName + "%'"
  86. }
  87. if RecUnitReason != "" {
  88. where = where + " and RecUnitReason like '%" + RecUnitReason + "%'"
  89. }
  90. if RecUnitPerson != "" {
  91. where = where + " and RecUnitPerson like '%" + RecUnitPerson + "%'"
  92. }
  93. if RecDate != "" {
  94. where = where + " and RecDate like '%" + RecDate + "%'"
  95. }
  96. if RecUnitId != "" {
  97. where = where + " and RecUnitId like '%" + RecUnitId + "%'"
  98. }
  99. if RecUnitName != "" {
  100. where = where + " and RecUnitName like '%" + RecUnitName + "%'"
  101. }
  102. if StatusA != "" {
  103. where = where + " and StatusA like '%" + StatusA + "%'"
  104. }
  105. if BackReason != "" {
  106. where = where + " and BackReason like '%" + BackReason + "%'"
  107. }
  108. if InFlag != "" {
  109. where = where + " and InFlag like '%" + InFlag + "%'"
  110. }
  111. if EffectStartTime != "" {
  112. where = where + " and EffectStartTime like '%" + EffectStartTime + "%'"
  113. }
  114. if EffectEndTime != "" {
  115. where = where + " and EffectEndTime like '%" + EffectEndTime + "%'"
  116. }
  117. if AuditProcessNote != "" {
  118. where = where + " and AuditProcessNote like '%" + AuditProcessNote + "%'"
  119. }
  120. if AuditDate != "" {
  121. where = where + " and AuditDate like '%" + AuditDate + "%'"
  122. }
  123. if PayNotice != "" {
  124. where = where + " and PayNotice like '%" + PayNotice + "%'"
  125. }
  126. if SupplierStatus != "" {
  127. where = where + " and SupplierStatus like '%" + SupplierStatus + "%'"
  128. }
  129. if MgrType != "" {
  130. where = where + " and MgrType like '%" + MgrType + "%'"
  131. }
  132. if Type != "" {
  133. where = where + " and Type like '%" + Type + "%'"
  134. }
  135. if MgrUnit != "" {
  136. where = where + " and MgrUnit like '%" + MgrUnit + "%'"
  137. }
  138. if AddinTime != "" {
  139. where = where + " and AddinTime like '%" + AddinTime + "%'"
  140. }
  141. if EffectTime != "" {
  142. where = where + " and EffectTime like '%" + EffectTime + "%'"
  143. }
  144. if ApplyTime != "" {
  145. where = where + " and ApplyTime like '%" + ApplyTime + "%'"
  146. }
  147. if SupplierNo != "" {
  148. where = where + " and SupplierNo like '%" + SupplierNo + "%'"
  149. }
  150. if MDMFlag != "" {
  151. where = where + " and MDMFlag like '%" + MDMFlag + "%'"
  152. }
  153. if InternalFlag != "" {
  154. where = where + " and InternalFlag like '%" + InternalFlag + "%'"
  155. }
  156. if ImportFlag != "" {
  157. where = where + " and ImportFlag like '%" + ImportFlag + "%'"
  158. }
  159. if OutsideFlog != "" {
  160. where = where + " and OutsideFlog like '%" + OutsideFlog + "%'"
  161. }
  162. if Remark != "" {
  163. where = where + " and Remark like '%" + Remark + "%'"
  164. }
  165. if IsDelete != "" {
  166. where = where + " and IsDelete like '%" + IsDelete + "%'"
  167. }
  168. if CreateOn != "" {
  169. where = where + " and CreateOn like '%" + CreateOn + "%'"
  170. }
  171. if CreateUserId != "" {
  172. where = where + " and CreateUserId like '%" + CreateUserId + "%'"
  173. }
  174. if CreateBy != "" {
  175. where = where + " and CreateBy like '%" + CreateBy + "%'"
  176. }
  177. if ModifiedOn != "" {
  178. where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
  179. }
  180. if ModifiedUserId != "" {
  181. where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
  182. }
  183. if ModifiedBy != "" {
  184. where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
  185. }
  186. if CreateOn != "" {
  187. dates := strings.Split(CreateOn, ",")
  188. if len(dates) == 2 {
  189. minDate := dates[0]
  190. maxDate := dates[1]
  191. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  192. }
  193. }
  194. svc := suppliercert.GetOilSupplierCertService(utils.DBE)
  195. var list []suppliercert.OilSupplierCert
  196. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  197. var datainfo DataInfo
  198. datainfo.Items = list
  199. datainfo.CurrentItemCount = total
  200. datainfo.PageIndex = page.CurrentPage
  201. datainfo.ItemsPerPage = page.Size
  202. this.Data["json"] = &datainfo
  203. this.ServeJSON()
  204. }
  205. // @Title 获取字典列表
  206. // @Description get user by token
  207. // @Success 200 {object} map[string]interface{}
  208. // @router /dictlist [get]
  209. func (this *OilSupplierCertController) GetDictList() {
  210. dictList := make(map[string]interface{})
  211. //dictSvc := items.GetItemsService(utils.DBE)
  212. userSvc := baseUser.GetBaseUserService(utils.DBE)
  213. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  214. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", this.User.AccCode)
  215. var userEntity userRole.Base_User
  216. userSvc.GetEntityById(this.User.Id, &userEntity)
  217. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId(this.User.AccCode, userEntity.Departmentid)
  218. //var dictCustomer []svccustomer.Customer
  219. //customerSvc.GetEntitysByWhere(this.User.AccCode + CustomerName, "", &dictCustomer)
  220. //dictList["EntrustCorp"] = &dictCustomer
  221. var datainfo DataInfo
  222. datainfo.Items = dictList
  223. this.Data["json"] = &datainfo
  224. this.ServeJSON()
  225. }
  226. // @Title 获取实体
  227. // @Description 获取实体
  228. // @Success 200 {object} suppliercert.OilSupplierCert
  229. // @router /get/:id [get]
  230. func (this *OilSupplierCertController) GetEntity() {
  231. Id := this.Ctx.Input.Param(":id")
  232. var model suppliercert.OilSupplierCert
  233. svc := suppliercert.GetOilSupplierCertService(utils.DBE)
  234. svc.GetEntityByIdBytbl(OilSupplierCertName, Id, &model)
  235. this.Data["json"] = &model
  236. this.ServeJSON()
  237. }
  238. // @Title 获取实体
  239. // @Description 获取实体
  240. // @Success 200 {object} suppliercert.OilSupplierCert
  241. // @router /getbycreatorandtype/:typecode [get]
  242. func (this *OilSupplierCertController) GetEntityByCreatorId() {
  243. creatorId := this.User.Id
  244. typeCode := this.Ctx.Input.Param(":typecode")
  245. var model suppliercert.OilSupplierCert
  246. svc := suppliercert.GetOilSupplierCertService(utils.DBE)
  247. where := " CreateUserId = '" + creatorId + "'"
  248. where += " and SupplierTypeCode = '" + typeCode + "'"
  249. svc.GetEntityByWhere(OilSupplierCertName, where, &model)
  250. this.Data["json"] = &model
  251. this.ServeJSON()
  252. }
  253. // @Title 添加
  254. // @Description 新增
  255. // @Success 200 {object} controllers.Request
  256. // @router /add [post]
  257. func (this *OilSupplierCertController) AddEntity() {
  258. var model suppliercert.OilSupplierCert
  259. var jsonBlob = this.Ctx.Input.RequestBody
  260. svc := suppliercert.GetOilSupplierCertService(utils.DBE)
  261. json.Unmarshal(jsonBlob, &model)
  262. model.CreateOn = time.Now()
  263. model.CreateBy = this.User.Realname
  264. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  265. //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  266. _, err := svc.InsertEntityBytbl(OilSupplierCertName, &model)
  267. var errinfo ErrorDataInfo
  268. if err == nil {
  269. //新增
  270. errinfo.Message = "添加成功!"
  271. errinfo.Code = 0
  272. errinfo.Item = model.Id
  273. this.Data["json"] = &errinfo
  274. this.ServeJSON()
  275. } else {
  276. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  277. errinfo.Code = -1
  278. this.Data["json"] = &errinfo
  279. this.ServeJSON()
  280. }
  281. }
  282. // @Title 修改实体
  283. // @Description 修改实体
  284. // @Success 200 {object} controllers.Request
  285. // @router /update/:id [post]
  286. func (this *OilSupplierCertController) UpdateEntity() {
  287. id := this.Ctx.Input.Param(":id")
  288. var errinfo ErrorInfo
  289. if id == "" {
  290. errinfo.Message = "操作失败!请求信息不完整"
  291. errinfo.Code = -2
  292. this.Data["json"] = &errinfo
  293. this.ServeJSON()
  294. return
  295. }
  296. var model suppliercert.OilSupplierCert
  297. svc := suppliercert.GetOilSupplierCertService(utils.DBE)
  298. var jsonBlob = this.Ctx.Input.RequestBody
  299. json.Unmarshal(jsonBlob, &model)
  300. model.ModifiedOn = time.Now()
  301. model.ModifiedBy = this.User.Realname
  302. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  303. cols := []string{
  304. "Id",
  305. "SupplierId",
  306. "AccessCardNo",
  307. "SupplierTypeCode",
  308. "SupplierTypeName",
  309. "RecUnitReason",
  310. "RecUnitPerson",
  311. "RecDate",
  312. "RecUnitId",
  313. "RecUnitName",
  314. "Status",
  315. "BackReason",
  316. "InFlag",
  317. "EffectStartTime",
  318. "EffectEndTime",
  319. "AuditProcessNote",
  320. "AuditDate",
  321. "PayNotice",
  322. "SupplierStatus",
  323. "MgrType",
  324. "Type",
  325. "MgrUnit",
  326. "AddinTime",
  327. "EffectTime",
  328. "ApplyTime",
  329. "SupplierNo",
  330. "MDMFlag",
  331. "InternalFlag",
  332. "ImportFlag",
  333. "OutsideFlog",
  334. "Remark",
  335. "IsDelete",
  336. "CreateOn",
  337. "CreateUserId",
  338. "CreateBy",
  339. "ModifiedOn",
  340. "ModifiedUserId",
  341. "ModifiedBy",
  342. }
  343. err := svc.UpdateEntityBytbl(OilSupplierCertName, id, &model, cols)
  344. if err == nil {
  345. errinfo.Message = "修改成功!"
  346. errinfo.Code = 0
  347. this.Data["json"] = &errinfo
  348. this.ServeJSON()
  349. } else {
  350. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  351. errinfo.Code = -1
  352. this.Data["json"] = &errinfo
  353. this.ServeJSON()
  354. }
  355. }
  356. // @Title 删除单条信息
  357. // @Description
  358. // @Success 200 {object} ErrorInfo
  359. // @Failure 403 :id 为空
  360. // @router /delete/:Id [delete]
  361. func (this *OilSupplierCertController) DeleteEntity() {
  362. Id := this.Ctx.Input.Param(":Id")
  363. var errinfo ErrorInfo
  364. if Id == "" {
  365. errinfo.Message = "操作失败!请求信息不完整"
  366. errinfo.Code = -2
  367. this.Data["json"] = &errinfo
  368. this.ServeJSON()
  369. return
  370. }
  371. var model suppliercert.OilSupplierCert
  372. var entityempty suppliercert.OilSupplierCert
  373. svc := suppliercert.GetOilSupplierCertService(utils.DBE)
  374. opdesc := "删除-" + Id
  375. err := svc.DeleteOperationAndWriteLogBytbl(OilSupplierCertName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报")
  376. if err == nil {
  377. errinfo.Message = "删除成功"
  378. errinfo.Code = 0
  379. this.Data["json"] = &errinfo
  380. this.ServeJSON()
  381. } else {
  382. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  383. errinfo.Code = -1
  384. this.Data["json"] = &errinfo
  385. this.ServeJSON()
  386. }
  387. }
  388. // @Title 提交审批
  389. // @Description 提交审批
  390. // @Success 200 {object} controllers.Request
  391. // @router /audit/:id [post]
  392. func (this *OilSupplierCertController) AuditEntity() {
  393. certId := this.Ctx.Input.Param(":id")
  394. var errinfo ErrorDataInfo
  395. defer func() { //finally处理失败的异常
  396. if err := recover(); err != nil {
  397. errinfo.Message = "提交失败," + err.(string)
  398. errinfo.Code = -1
  399. this.Data["json"] = &errinfo
  400. this.ServeJSON()
  401. } else {
  402. //返回正确结果
  403. errinfo.Message = "审核提交成功"
  404. errinfo.Code = 0
  405. this.Data["json"] = &errinfo
  406. this.ServeJSON()
  407. }
  408. }()
  409. //取出审批列表
  410. certSrv := suppliercert.GetOilSupplierCertService(utils.DBE)
  411. processInstanceId := certSrv.SubmitOrgAudit(certId, workflow.OIL_SUPPLIER_APPLY, workflow.FIRST_TRIAL, this.User.Id, "1", "提交给二级单位初审", OilSupplierCertSubName, OilClassOrgSettingName)
  412. //记下workflowID(首次提交时才会记录,中间状态请忽略) 及审批状态
  413. var supplierCertEntity suppliercert.OilSupplierCert
  414. certSrv.GetEntityById(certId, supplierCertEntity)
  415. supplierCertEntity.WorkflowId = processInstanceId
  416. supplierCertEntity.Status = suppliercert.FIRST_TRIAL_STATUS //二级单位初审
  417. supplierCertEntity.Step = 4
  418. cols := []string{
  419. "Id",
  420. "WorkflowId",
  421. "Status",
  422. "Step",
  423. }
  424. certSrv.UpdateEntityByIdCols(certId, supplierCertEntity, cols)
  425. }
  426. //// @Title 提交二级审批
  427. //// @Description 提交二级审批
  428. //// @Param body body suppliercert.OilSupplierCert
  429. //// @Success 200 {object} controllers.Request
  430. //// @router /audit/:id [post]
  431. //func (this *OilSupplierCertController) AuditEntity() {
  432. // certId := this.Ctx.Input.Param(":id")
  433. // var errinfo ErrorDataInfo
  434. // defer func() { //finally处理失败的异常
  435. // if err := recover(); err != nil {
  436. // errinfo.Message = "提交失败," + err.(string)
  437. // errinfo.Code = -1
  438. // this.Data["json"] = &errinfo
  439. // this.ServeJSON()
  440. // } else {
  441. // //返回正确结果
  442. // errinfo.Message = "审核提交成功"
  443. // errinfo.Code = 0
  444. // this.Data["json"] = &errinfo
  445. // this.ServeJSON()
  446. // }
  447. // }()
  448. // //取出审批列表
  449. // certSrv := suppliercert.GetOilSupplierCertService(utils.DBE)
  450. // processInstanceId := certSrv.SubmitOrgAudit(certId, workflow.OIL_SUPPLIER_APPLY, workflow.FIRST_TRIAL, this.User.Id, "1", "提交给二级单位初审", OilSupplierCertSubName, OilClassOrgSettingName)
  451. // //记下workflowID(首次提交时才会记录,中间状态请忽略) 及审批状态
  452. // var supplierCertEntity suppliercert.OilSupplierCert
  453. // certSrv.GetEntityById(certId, supplierCertEntity)
  454. // supplierCertEntity.WorkflowId = processInstanceId
  455. // supplierCertEntity.Status = suppliercert.FIRST_TRIAL_STATUS //二级单位初审
  456. // cols := []string{
  457. // "Id",
  458. // "WorkflowId",
  459. // "Status",
  460. // }
  461. // certSrv.UpdateEntityByIdCols(certId, supplierCertEntity, cols)
  462. //}