suppliercertsub.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. package oilsupplier
  2. import (
  3. "encoding/json"
  4. // "fmt"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "dashoo.cn/backend/api/business/baseUser"
  9. "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
  10. "dashoo.cn/backend/api/business/oilsupplier/supplierfile"
  11. // "dashoo.cn/backend/api/business/oilsupplier/technologyservice"
  12. . "dashoo.cn/backend/api/controllers"
  13. "dashoo.cn/business/userRole"
  14. "dashoo.cn/utils"
  15. )
  16. type OilSupplierCertSubController struct {
  17. BaseController
  18. }
  19. // @Title 获取列表
  20. // @Description get user by token
  21. // @Success 200 {object} []suppliercertsub.OilSupplierCertSub
  22. // @router /list [get]
  23. func (this *OilSupplierCertSubController) GetEntityList() {
  24. //获取分页信息
  25. page := this.GetPageInfoForm()
  26. where := " 1=1 "
  27. orderby := "Id"
  28. asc := false
  29. Order := this.GetString("Order")
  30. Prop := this.GetString("Prop")
  31. if Order != "" && Prop != "" {
  32. orderby = Prop
  33. if Order == "asc" {
  34. asc = true
  35. }
  36. }
  37. Id := this.GetString("Id")
  38. SupplierId := this.GetString("SupplierId")
  39. SupplierCertId := this.GetString("SupplierCertId")
  40. SupplierTypeCode := this.GetString("SubClassId")
  41. Code := this.GetString("Code")
  42. Name := this.GetString("Name")
  43. Remark := this.GetString("Remark")
  44. IsDelete := this.GetString("IsDelete")
  45. CreateOn := this.GetString("CreateOn")
  46. CreateUserId := this.GetString("CreateUserId")
  47. CreateBy := this.GetString("CreateBy")
  48. ModifiedOn := this.GetString("ModifiedOn")
  49. ModifiedUserId := this.GetString("ModifiedUserId")
  50. ModifiedBy := this.GetString("ModifiedBy")
  51. if Id != "" {
  52. where = where + " and Id like '%" + Id + "%'"
  53. }
  54. if SupplierId != "" {
  55. where = where + " and SupplierId like '%" + SupplierId + "%'"
  56. }
  57. if SupplierCertId != "" {
  58. where = where + " and SupplierCertId = '" + SupplierCertId + "'"
  59. }
  60. if SupplierTypeCode != "" {
  61. where = where + " and SupplierTypeCode = '" + SupplierTypeCode + "'"
  62. }
  63. if Code != "" {
  64. where = where + " and Code like '%" + Code + "%'"
  65. }
  66. if Name != "" {
  67. where = where + " and Name like '%" + Name + "%'"
  68. }
  69. if Remark != "" {
  70. where = where + " and Remark like '%" + Remark + "%'"
  71. }
  72. if IsDelete != "" {
  73. where = where + " and IsDelete like '%" + IsDelete + "%'"
  74. }
  75. if CreateOn != "" {
  76. where = where + " and CreateOn like '%" + CreateOn + "%'"
  77. }
  78. if CreateUserId != "" {
  79. where = where + " and CreateUserId like '%" + CreateUserId + "%'"
  80. }
  81. if CreateBy != "" {
  82. where = where + " and CreateBy like '%" + CreateBy + "%'"
  83. }
  84. if ModifiedOn != "" {
  85. where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
  86. }
  87. if ModifiedUserId != "" {
  88. where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
  89. }
  90. if ModifiedBy != "" {
  91. where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
  92. }
  93. if CreateOn != "" {
  94. dates := strings.Split(CreateOn, ",")
  95. if len(dates) == 2 {
  96. minDate := dates[0]
  97. maxDate := dates[1]
  98. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  99. }
  100. }
  101. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  102. var list []suppliercertsub.OilSupplierCertSub
  103. total := svc.GetPagingEntitiesWithoutAccCode(page.CurrentPage, page.Size, orderby, asc, &list, where)
  104. var datainfo DataInfo
  105. datainfo.Items = list
  106. datainfo.CurrentItemCount = total
  107. datainfo.PageIndex = page.CurrentPage
  108. datainfo.ItemsPerPage = page.Size
  109. this.Data["json"] = &datainfo
  110. this.ServeJSON()
  111. }
  112. // @Title 获取字典列表
  113. // @Description get user by token
  114. // @Success 200 {object} map[string]interface{}
  115. // @router /dictlist [get]
  116. func (this *OilSupplierCertSubController) GetDictList() {
  117. dictList := make(map[string]interface{})
  118. //dictSvc := items.GetItemsService(utils.DBE)
  119. userSvc := baseUser.GetBaseUserService(utils.DBE)
  120. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  121. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", this.User.AccCode)
  122. var userEntity userRole.Base_User
  123. userSvc.GetEntityById(this.User.Id, &userEntity)
  124. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId(this.User.AccCode, userEntity.Departmentid)
  125. //var dictCustomer []svccustomer.Customer
  126. //customerSvc.GetEntitysByWhere(this.User.AccCode + CustomerName, "", &dictCustomer)
  127. //dictList["EntrustCorp"] = &dictCustomer
  128. var datainfo DataInfo
  129. datainfo.Items = dictList
  130. this.Data["json"] = &datainfo
  131. this.ServeJSON()
  132. }
  133. // @Title 获取实体
  134. // @Description 获取实体
  135. // @Success 200 {object} suppliercertsub.OilSupplierCertSub
  136. // @router /get/:id [get]
  137. func (this *OilSupplierCertSubController) GetEntity() {
  138. Id := this.Ctx.Input.Param(":id")
  139. var model suppliercertsub.OilSupplierCertSub
  140. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  141. svc.GetEntityByIdBytbl(OilSupplierCertSubName, Id, &model)
  142. this.Data["json"] = &model
  143. this.ServeJSON()
  144. }
  145. // @Title 添加
  146. // @Description 新增
  147. // @Param body body suppliercertsub.OilSupplierCertSub
  148. // @Success 200 {object} controllers.Request
  149. // @router /add [post]
  150. func (this *OilSupplierCertSubController) AddEntity() {
  151. var model suppliercertsub.OilSupplierCertSub
  152. var jsonBlob = this.Ctx.Input.RequestBody
  153. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  154. json.Unmarshal(jsonBlob, &model)
  155. model.CreateOn = time.Now()
  156. model.CreateBy = this.User.Realname
  157. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  158. //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  159. _, err := svc.InsertEntityBytbl(OilSupplierCertSubName, &model)
  160. var errinfo ErrorDataInfo
  161. if err == nil {
  162. //新增
  163. errinfo.Message = "添加成功!"
  164. errinfo.Code = 0
  165. errinfo.Item = model.Id
  166. this.Data["json"] = &errinfo
  167. this.ServeJSON()
  168. } else {
  169. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  170. errinfo.Code = -1
  171. this.Data["json"] = &errinfo
  172. this.ServeJSON()
  173. }
  174. }
  175. // @Title 修改实体
  176. // @Description 修改实体
  177. // @Param body body suppliercertsub.OilSupplierCertSub
  178. // @Success 200 {object} controllers.Request
  179. // @router /update/:id [post]
  180. func (this *OilSupplierCertSubController) UpdateEntity() {
  181. id := this.Ctx.Input.Param(":id")
  182. var errinfo ErrorInfo
  183. if id == "" {
  184. errinfo.Message = "操作失败!请求信息不完整"
  185. errinfo.Code = -2
  186. this.Data["json"] = &errinfo
  187. this.ServeJSON()
  188. return
  189. }
  190. var model suppliercertsub.OilSupplierCertSub
  191. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  192. var jsonBlob = this.Ctx.Input.RequestBody
  193. json.Unmarshal(jsonBlob, &model)
  194. model.ModifiedOn = time.Now()
  195. model.ModifiedBy = this.User.Realname
  196. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  197. cols := []string{
  198. "Id",
  199. "SupplierId",
  200. "SupplierCertId",
  201. "SubClassId",
  202. "Code",
  203. "Name",
  204. "Remark",
  205. "IsDelete",
  206. "CreateOn",
  207. "CreateUserId",
  208. "CreateBy",
  209. "ModifiedOn",
  210. "ModifiedUserId",
  211. "ModifiedBy",
  212. }
  213. err := svc.UpdateEntityBytbl(OilSupplierCertSubName, id, &model, cols)
  214. if err == nil {
  215. errinfo.Message = "修改成功!"
  216. errinfo.Code = 0
  217. this.Data["json"] = &errinfo
  218. this.ServeJSON()
  219. } else {
  220. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  221. errinfo.Code = -1
  222. this.Data["json"] = &errinfo
  223. this.ServeJSON()
  224. }
  225. }
  226. // @Title 删除单条信息
  227. // @Description
  228. // @Success 200 {object} ErrorInfo
  229. // @Failure 403 :id 为空
  230. // @router /delete/:Id [delete]
  231. func (this *OilSupplierCertSubController) DeleteEntity() {
  232. Id := this.Ctx.Input.Param(":Id")
  233. var errinfo ErrorInfo
  234. if Id == "" {
  235. errinfo.Message = "操作失败!请求信息不完整"
  236. errinfo.Code = -2
  237. this.Data["json"] = &errinfo
  238. this.ServeJSON()
  239. return
  240. }
  241. var model suppliercertsub.OilSupplierCertSub
  242. var entityempty suppliercertsub.OilSupplierCertSub
  243. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  244. opdesc := "删除-" + Id
  245. err := svc.DeleteOperationAndWriteLogBytbl(OilSupplierCertSubName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报")
  246. if err == nil {
  247. errinfo.Message = "删除成功"
  248. errinfo.Code = 0
  249. this.Data["json"] = &errinfo
  250. this.ServeJSON()
  251. } else {
  252. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  253. errinfo.Code = -1
  254. this.Data["json"] = &errinfo
  255. this.ServeJSON()
  256. }
  257. }
  258. // @Title 新增准入范围
  259. // @Description 新增准入范围
  260. // @Success 200 {object} controllers.Request
  261. // @router /addbusiness [post]
  262. func (this *OilSupplierCertSubController) AddBusiness() {
  263. var model suppliercertsub.OilSupplierCertSub
  264. var jsonblob = this.Ctx.Input.RequestBody
  265. json.Unmarshal(jsonblob, &model)
  266. model.CreateBy = this.User.Realname
  267. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  268. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  269. _, err := svc.InsertEntityBytbl(OilSupplierCertSubName, &model)
  270. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  271. needList := filesvc.GetTechNeedFileList(model.SubClassId)
  272. if err == nil {
  273. var list []suppliercertsub.OilSupplierCertSub
  274. where := "SupplierId = '" + strconv.Itoa(model.SupplierId) + "'"
  275. where += " and SupplierCertId = '" + strconv.Itoa(model.SupplierCertId) + "'"
  276. svc.GetEntitysByWhere(OilSupplierCertSubName, where, &list)
  277. if len(list) == 1 { //第一次添加准入项,将共有必备资质写入文件表
  278. for i := 0; i < len(needList); i++ {
  279. var entity supplierfile.OilSupplierFile
  280. entity.SupplierId = model.SupplierId
  281. entity.SupplierTypeCode = model.SupplierTypeCode
  282. entity.NeedFileType = needList[i].FileName
  283. entity.FileType = 1
  284. entity.CreateBy = this.User.Realname
  285. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  286. svc.InsertEntityBytbl(OilSupplierFileName, &entity)
  287. }
  288. } else {
  289. if len(needList) > 4 {
  290. for i := 4; i < len(needList); i++ {
  291. var entity supplierfile.OilSupplierFile
  292. entity.SupplierId = model.SupplierId
  293. entity.SupplierTypeCode = model.SupplierTypeCode
  294. entity.NeedFileType = needList[i].FileName
  295. entity.FileType = 1
  296. entity.CreateBy = this.User.Realname
  297. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  298. svc.InsertEntityBytbl(OilSupplierFileName, &entity)
  299. }
  300. }
  301. }
  302. }
  303. var errinfo ErrorDataInfo
  304. if err == nil {
  305. errinfo.Message = "操作成功!"
  306. errinfo.Code = 0
  307. errinfo.Item = model.Id
  308. this.Data["json"] = &errinfo
  309. this.ServeJSON()
  310. } else {
  311. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  312. errinfo.Code = -1
  313. this.Data["json"] = &errinfo
  314. this.ServeJSON()
  315. }
  316. }
  317. // @Title 更新准入范围
  318. // @Description 更新准入范围
  319. // @Param id path string true
  320. // @Success 200 {object}
  321. // @router /editbusiness/:id [put]
  322. func (this *OilSupplierCertSubController) EditBusiness() {
  323. id := this.Ctx.Input.Param(":id")
  324. var errinfo ErrorInfo
  325. if id == "" {
  326. errinfo.Message = "操作失败!请求信息不完整"
  327. errinfo.Code = -2
  328. this.Data["json"] = &errinfo
  329. this.ServeJSON()
  330. return
  331. }
  332. var model suppliercertsub.OilSupplierCertSub
  333. var jsonblob = this.Ctx.Input.RequestBody
  334. json.Unmarshal(jsonblob, &model)
  335. var entity suppliercertsub.OilSupplierCertSub
  336. model.ModifiedBy = this.User.Realname
  337. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  338. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  339. opdesc := "编辑准入范围-" + model.Name
  340. var cols []string = []string{"SubClassId", "Name", "Code", "Remark", "IsDelete", "ModifiedBy", "ModifiedUserId"}
  341. err := svc.UpdateOperationAndWriteLogBytbl(OilSupplierCertSubName, BaseOperationLogName, id, &model, &entity, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "准入范围")
  342. if err == nil {
  343. errinfo.Message = "操作成功!"
  344. errinfo.Code = 0
  345. this.Data["json"] = &errinfo
  346. this.ServeJSON()
  347. } else {
  348. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  349. errinfo.Code = -1
  350. this.Data["json"] = &errinfo
  351. this.ServeJSON()
  352. }
  353. }
  354. // @Title 删除准入范围
  355. // @Description
  356. // @Success 200 {object} ErrorInfo
  357. // @Failure 403 :id 为空
  358. // @router /businessdelete/:Id [delete]
  359. func (this *OilSupplierCertSubController) BusinessDelete() {
  360. Id := this.Ctx.Input.Param(":Id")
  361. var errinfo ErrorInfo
  362. if Id == "" {
  363. errinfo.Message = "操作失败!请求信息不完整"
  364. errinfo.Code = -2
  365. this.Data["json"] = &errinfo
  366. this.ServeJSON()
  367. return
  368. }
  369. where := " Id= " + Id
  370. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  371. err := svc.DeleteEntityBytbl(OilSupplierCertSubName, where)
  372. if err == nil {
  373. errinfo.Message = "删除成功"
  374. errinfo.Code = 0
  375. this.Data["json"] = &errinfo
  376. this.ServeJSON()
  377. } else {
  378. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  379. errinfo.Code = -1
  380. this.Data["json"] = &errinfo
  381. this.ServeJSON()
  382. }
  383. }
  384. // @Title 获取待审核业务列表
  385. // @Description get user by token
  386. // @Success 200 {object} models.Userblood
  387. // @router /auditbuslist [get]
  388. func (this *OilSupplierCertSubController) AuditbusList() {
  389. var list []suppliercertsub.OilSupplierCertSub
  390. //获取分页信息
  391. page := this.GetPageInfoForm()
  392. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  393. orderby := "CreateOn desc"
  394. Order := this.GetString("Order")
  395. Prop := this.GetString("Prop")
  396. if Order != "" && Prop != "" {
  397. orderby = Prop + " " + Order
  398. }
  399. where := "1 = 1"
  400. where += " and c.Id = '" + this.User.Id + "'"
  401. SupplierCertId := this.GetString("SupplierCertId")
  402. SupplierTypeCode := this.GetString("SupplierTypeCode")
  403. if SupplierCertId != "" {
  404. where = where + " and a.SupplierCertId = '" + SupplierCertId + "'"
  405. }
  406. if SupplierTypeCode != "" {
  407. where = where + " and a.SupplierTypeCode = '" + SupplierTypeCode + "'"
  408. }
  409. total, list := svc.GetWaitAuditBusinesslist(page.CurrentPage, page.Size, orderby, OilSupplierCertSubName, OilClassOrgSettingName, where)
  410. var datainfo DataInfo
  411. datainfo.Items = list
  412. datainfo.CurrentItemCount = total
  413. this.Data["json"] = &datainfo
  414. this.ServeJSON()
  415. }
  416. // @Title 获取审核意见列表
  417. // @Description 获取审核意见列表
  418. // @Success 200 {object} controllers.Request
  419. // @router /opinionlist [get]
  420. func (this *OilSupplierCertSubController) OpinionList() {
  421. SupplierCertSubId := this.GetString("SupplierCertSubId")
  422. var list []suppliercertsub.OilSupplierOpinion
  423. where := " 1 = 1 "
  424. if SupplierCertSubId != "" {
  425. where = where + " and SupplierCertSubId = '" + SupplierCertSubId + "'"
  426. }
  427. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  428. svc.GetEntitysByWhere(OilSupplierOpinionName, where, &list)
  429. var datainfo DataInfo
  430. datainfo.Items = list
  431. this.Data["json"] = &datainfo
  432. this.ServeJSON()
  433. }
  434. // @Title 新增审核意见
  435. // @Description 新增审核意见
  436. // @Success 200 {object} controllers.Request
  437. // @router /addopinion [post]
  438. func (this *OilSupplierCertSubController) AddOpinion() {
  439. var model suppliercertsub.OilSupplierOpinion
  440. var jsonblob = this.Ctx.Input.RequestBody
  441. json.Unmarshal(jsonblob, &model)
  442. model.AuditorName = this.User.Realname
  443. model.AuditorId, _ = utils.StrTo(this.User.Id).Int()
  444. model.CreateBy = this.User.Realname
  445. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  446. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  447. _, err := svc.InsertEntityBytbl(OilSupplierOpinionName, &model)
  448. var errinfo ErrorDataInfo
  449. if err == nil {
  450. errinfo.Message = "操作成功!"
  451. errinfo.Code = 0
  452. errinfo.Item = model.Id
  453. this.Data["json"] = &errinfo
  454. this.ServeJSON()
  455. } else {
  456. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  457. errinfo.Code = -1
  458. this.Data["json"] = &errinfo
  459. this.ServeJSON()
  460. }
  461. }