suppliercert.go 15 KB

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