suppliercertsub.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. package oilsupplier
  2. import (
  3. "dashoo.cn/backend/api/business/oilsupplier/supplier"
  4. "dashoo.cn/backend/api/business/oilsupplier/suppliercert"
  5. "dashoo.cn/business/parameter"
  6. "encoding/json"
  7. //"fmt"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "dashoo.cn/backend/api/business/baseUser"
  12. "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
  13. "dashoo.cn/backend/api/business/oilsupplier/supplierfile"
  14. // "dashoo.cn/backend/api/business/oilsupplier/technologyservice"
  15. . "dashoo.cn/backend/api/controllers"
  16. "dashoo.cn/business/userRole"
  17. "dashoo.cn/utils"
  18. )
  19. type OilSupplierCertSubController struct {
  20. BaseController
  21. }
  22. // @Title 获取列表
  23. // @Description get user by token
  24. // @Success 200 {object} []suppliercertsub.OilSupplierCertSub
  25. // @router /list [get]
  26. func (this *OilSupplierCertSubController) GetEntityList() {
  27. //获取分页信息
  28. page := this.GetPageInfoForm()
  29. where := " 1=1 "
  30. orderby := "Id"
  31. asc := false
  32. Order := this.GetString("Order")
  33. Prop := this.GetString("Prop")
  34. if Order != "" && Prop != "" {
  35. orderby = Prop
  36. if Order == "asc" {
  37. asc = true
  38. }
  39. }
  40. Id := this.GetString("Id")
  41. SupplierId := this.GetString("SupplierId")
  42. SupplierCertId := this.GetString("SupplierCertId")
  43. SupplierTypeCode := this.GetString("SupplierTypeCode")
  44. Code := this.GetString("Code")
  45. Name := this.GetString("Name")
  46. Remark := this.GetString("Remark")
  47. IsDelete := this.GetString("IsDelete")
  48. CreateOn := this.GetString("CreateOn")
  49. CreateUserId := this.GetString("CreateUserId")
  50. CreateBy := this.GetString("CreateBy")
  51. ModifiedOn := this.GetString("ModifiedOn")
  52. ModifiedUserId := this.GetString("ModifiedUserId")
  53. ModifiedBy := this.GetString("ModifiedBy")
  54. if Id != "" {
  55. where = where + " and Id like '%" + Id + "%'"
  56. }
  57. if SupplierId != "" {
  58. where = where + " and SupplierId like '%" + SupplierId + "%'"
  59. }
  60. if SupplierCertId != "" {
  61. where = where + " and SupplierCertId = '" + SupplierCertId + "'"
  62. }
  63. if SupplierTypeCode != "" {
  64. where = where + " and SupplierTypeCode = '" + SupplierTypeCode + "'"
  65. }
  66. if Code != "" {
  67. where = where + " and Code like '%" + Code + "%'"
  68. }
  69. if Name != "" {
  70. where = where + " and Name like '%" + Name + "%'"
  71. }
  72. if Remark != "" {
  73. where = where + " and Remark like '%" + Remark + "%'"
  74. }
  75. if IsDelete != "" {
  76. where = where + " and IsDelete like '%" + IsDelete + "%'"
  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. where = where + " and Type = '1'"
  102. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  103. var list []suppliercertsub.OilSupplierCertSub
  104. total := svc.GetPagingEntitiesWithoutAccCode(page.CurrentPage, page.Size, orderby, asc, &list, where)
  105. var datainfo DataInfo
  106. datainfo.Items = list
  107. datainfo.CurrentItemCount = total
  108. datainfo.PageIndex = page.CurrentPage
  109. datainfo.ItemsPerPage = page.Size
  110. this.Data["json"] = &datainfo
  111. this.ServeJSON()
  112. }
  113. // @Title 获取字典列表
  114. // @Description get user by token
  115. // @Success 200 {object} map[string]interface{}
  116. // @router /dictlist [get]
  117. func (this *OilSupplierCertSubController) GetDictList() {
  118. dictList := make(map[string]interface{})
  119. //dictSvc := items.GetItemsService(utils.DBE)
  120. userSvc := baseUser.GetBaseUserService(utils.DBE)
  121. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  122. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", this.User.AccCode)
  123. var userEntity userRole.Base_User
  124. userSvc.GetEntityById(this.User.Id, &userEntity)
  125. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId(this.User.AccCode, userEntity.Departmentid)
  126. //var dictCustomer []svccustomer.Customer
  127. //customerSvc.GetEntitysByWhere(this.User.AccCode + CustomerName, "", &dictCustomer)
  128. //dictList["EntrustCorp"] = &dictCustomer
  129. var datainfo DataInfo
  130. datainfo.Items = dictList
  131. this.Data["json"] = &datainfo
  132. this.ServeJSON()
  133. }
  134. // @Title 获取实体
  135. // @Description 获取实体
  136. // @Success 200 {object} suppliercertsub.OilSupplierCertSub
  137. // @router /get/:id [get]
  138. func (this *OilSupplierCertSubController) GetEntity() {
  139. Id := this.Ctx.Input.Param(":id")
  140. var model suppliercertsub.OilSupplierCertSub
  141. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  142. svc.GetEntityByIdBytbl(OilSupplierCertSubName, Id, &model)
  143. this.Data["json"] = &model
  144. this.ServeJSON()
  145. }
  146. // @Title 添加
  147. // @Description 新增
  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. // @Success 200 {object} controllers.Request
  178. // @router /update/:id [post]
  179. func (this *OilSupplierCertSubController) UpdateEntity() {
  180. id := this.Ctx.Input.Param(":id")
  181. var errinfo ErrorInfo
  182. if id == "" {
  183. errinfo.Message = "操作失败!请求信息不完整"
  184. errinfo.Code = -2
  185. this.Data["json"] = &errinfo
  186. this.ServeJSON()
  187. return
  188. }
  189. var model suppliercertsub.OilSupplierCertSub
  190. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  191. var jsonBlob = this.Ctx.Input.RequestBody
  192. json.Unmarshal(jsonBlob, &model)
  193. model.ModifiedOn = time.Now()
  194. model.ModifiedBy = this.User.Realname
  195. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  196. cols := []string{
  197. "Id",
  198. "SupplierId",
  199. "SupplierCertId",
  200. "SubClassId",
  201. "Code",
  202. "Name",
  203. "Remark",
  204. "IsDelete",
  205. "CreateOn",
  206. "CreateUserId",
  207. "CreateBy",
  208. "ModifiedOn",
  209. "ModifiedUserId",
  210. "ModifiedBy",
  211. }
  212. err := svc.UpdateEntityBytbl(OilSupplierCertSubName, id, &model, cols)
  213. if err == nil {
  214. errinfo.Message = "修改成功!"
  215. errinfo.Code = 0
  216. this.Data["json"] = &errinfo
  217. this.ServeJSON()
  218. } else {
  219. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  220. errinfo.Code = -1
  221. this.Data["json"] = &errinfo
  222. this.ServeJSON()
  223. }
  224. }
  225. // @Title 删除单条信息
  226. // @Description
  227. // @Success 200 {object} ErrorInfo
  228. // @Failure 403 :id 为空
  229. // @router /delete/:Id [delete]
  230. func (this *OilSupplierCertSubController) DeleteEntity() {
  231. Id := this.Ctx.Input.Param(":Id")
  232. var errinfo ErrorInfo
  233. if Id == "" {
  234. errinfo.Message = "操作失败!请求信息不完整"
  235. errinfo.Code = -2
  236. this.Data["json"] = &errinfo
  237. this.ServeJSON()
  238. return
  239. }
  240. var model suppliercertsub.OilSupplierCertSub
  241. var entityempty suppliercertsub.OilSupplierCertSub
  242. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  243. opdesc := "删除-" + Id
  244. err := svc.DeleteOperationAndWriteLogBytbl(OilSupplierCertSubName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报")
  245. if err == nil {
  246. errinfo.Message = "删除成功"
  247. errinfo.Code = 0
  248. this.Data["json"] = &errinfo
  249. this.ServeJSON()
  250. } else {
  251. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  252. errinfo.Code = -1
  253. this.Data["json"] = &errinfo
  254. this.ServeJSON()
  255. }
  256. }
  257. // @Title 批量添加准入范围--物资类
  258. // @Description 批量添加准入范围
  259. // @Success 200 {object} business.device.DeviceChannels
  260. // @router /addgoodsbus [post]
  261. func (this *OilSupplierCertSubController) AddGoodsBus() {
  262. var jsonblob = this.Ctx.Input.RequestBody
  263. var datamain suppliercertsub.OilSupplierCertSub
  264. var dataother suppliercertsub.SupplierCertSubModel
  265. json.Unmarshal(jsonblob, &datamain)
  266. json.Unmarshal(jsonblob, &dataother)
  267. var supplierCertModel suppliercert.OilSupplierCert
  268. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  269. svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel)
  270. var supplierModel supplier.OilSupplier
  271. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  272. svcSupplier.GetEntityById(datamain.SupplierCertId, &supplierModel)
  273. for n := 0; n < len(dataother.CheckList); n++ {
  274. where_sub := "SupplierTypeCode = 01 and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  275. where_sub += " and SupplierCertId = '" + strconv.Itoa(dataother.SupplierCertId) + "'"
  276. where_sub += " and SubClassId = '" + dataother.CheckList[n].Id + "'"
  277. var model suppliercertsub.OilSupplierCertSub
  278. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  279. has := svc.GetEntityByWhere(OilSupplierCertSubName, where_sub, &model)
  280. if !has {
  281. datamain.SubClassId, _ = utils.StrTo(dataother.CheckList[n].Id).Int()
  282. datamain.Code = dataother.CheckList[n].Code
  283. datamain.Name = dataother.CheckList[n].Name
  284. datamain.Remark = dataother.Remark
  285. datamain.IsDelete = 0
  286. datamain.CreateBy = this.User.Realname
  287. datamain.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  288. svc.InsertEntityBytbl(OilSupplierCertSubName, &datamain)
  289. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  290. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  291. needList := filesvc.GetGoodsNeedFileList(dataother.CheckList[n].Id)
  292. if supplierCertModel.InStyle == "4" {
  293. var needFile supplierfile.FileList
  294. //战略合作协议扫描件
  295. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  296. needList = append(needList, needFile)
  297. }
  298. var list []supplierfile.OilSupplierFile
  299. where := "SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  300. svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
  301. //三证合一或五证合一不需要的字段
  302. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  303. //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件,"
  304. mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName")
  305. for i := 0; i < len(needList); i++ {
  306. var entity supplierfile.OilSupplierFile
  307. entity.SupplierId = dataother.SupplierId
  308. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了
  309. continue
  310. }
  311. //加入对应表OilSupplierCert2File
  312. var cert2File suppliercertsub.OilSupplierCert2File //创建结构体
  313. cert2File.SupplierId = dataother.SupplierId
  314. cert2File.SupplierCertId = dataother.SupplierCertId
  315. cert2File.SupplierTypeCode = dataother.SupplierTypeCode
  316. cert2File.SubClassId, _ = utils.StrTo(dataother.CheckList[n].Id).Int()
  317. cert2File.Code = dataother.CheckList[n].Code
  318. cert2File.Name = dataother.CheckList[n].Name
  319. cert2File.NeedFileType = needList[i].FileName
  320. svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File)
  321. if strings.Contains(mustField, needList[i].FileName+",") {
  322. entity.SupplierTypeCode = "000"
  323. } else {
  324. entity.SupplierTypeCode = dataother.SupplierTypeCode
  325. }
  326. entity.NeedFileType = needList[i].FileName
  327. entity.FileType = 1
  328. entity.EffectDate = time.Now()
  329. entity.CreateBy = this.User.Realname
  330. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  331. entity.SupType = 1
  332. isRepeat := false
  333. for j := 0; j < len(list); j++ {
  334. if list[j].NeedFileType == needList[i].FileName{
  335. isRepeat = true
  336. break
  337. }
  338. }
  339. if isRepeat == true {
  340. continue
  341. }
  342. svc.InsertEntityBytbl(OilSupplierFileName, &entity)
  343. }
  344. }
  345. }
  346. var errinfo ErrorDataInfo
  347. errinfo.Message = "操作成功!"
  348. errinfo.Code = 0
  349. this.Data["json"] = &errinfo
  350. this.ServeJSON()
  351. }
  352. // @Title 批量添加准入范围--技术服务类
  353. // @Description 批量添加准入范围
  354. // @Success 200 {object} business.device.DeviceChannels
  355. // @router /addtechbus [post]
  356. func (this *OilSupplierCertSubController) AddTechBus() {
  357. var jsonblob = this.Ctx.Input.RequestBody
  358. var datamain suppliercertsub.OilSupplierCertSub
  359. var dataother suppliercertsub.TechnologySubModel
  360. json.Unmarshal(jsonblob, &datamain)
  361. json.Unmarshal(jsonblob, &dataother)
  362. var supplierCertModel suppliercert.OilSupplierCert
  363. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  364. svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel)
  365. var supplierModel supplier.OilSupplier
  366. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  367. svcSupplier.GetEntityById(datamain.SupplierCertId, &supplierModel)
  368. for n := 0; n < len(dataother.CheckList); n++ {
  369. where_sub := "SupplierTypeCode = 03 and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  370. where_sub += " and SupplierCertId = '" + strconv.Itoa(dataother.SupplierCertId) + "'"
  371. where_sub += " and SubClassId = '" + strconv.Itoa(dataother.CheckList[n].Id) + "'"
  372. var model suppliercertsub.OilSupplierCertSub
  373. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  374. has := svc.GetEntityByWhere(OilSupplierCertSubName, where_sub, &model)
  375. if !has {
  376. datamain.SubClassId = dataother.CheckList[n].Id
  377. datamain.Code = dataother.CheckList[n].Code
  378. datamain.Name = dataother.CheckList[n].Name
  379. datamain.Remark = dataother.Remark
  380. datamain.IsDelete = 0
  381. datamain.CreateBy = this.User.Realname
  382. datamain.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  383. svc.InsertEntityBytbl(OilSupplierCertSubName, &datamain)
  384. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  385. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  386. needList := filesvc.GetTechNeedFileList(dataother.CheckList[n].Id)
  387. if supplierCertModel.InStyle == "4" {
  388. var needFile supplierfile.FileList
  389. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  390. needList = append(needList, needFile)
  391. }
  392. var list []supplierfile.OilSupplierFile
  393. where := "SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  394. svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
  395. //三证合一或五证合一不需要的字段
  396. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  397. //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件,"
  398. mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName")
  399. for i := 0; i < len(needList); i++ {
  400. var entity supplierfile.OilSupplierFile
  401. entity.SupplierId = dataother.SupplierId
  402. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了
  403. continue
  404. }
  405. //加入对应表OilSupplierCert2File
  406. var cert2File suppliercertsub.OilSupplierCert2File //创建结构体
  407. cert2File.SupplierId = dataother.SupplierId
  408. cert2File.SupplierCertId = dataother.SupplierCertId
  409. cert2File.SupplierTypeCode = dataother.SupplierTypeCode
  410. cert2File.SubClassId= dataother.CheckList[n].Id
  411. cert2File.Code = dataother.CheckList[n].Code
  412. cert2File.Name = dataother.CheckList[n].Name
  413. cert2File.NeedFileType = needList[i].FileName
  414. svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File)
  415. if strings.Contains(mustField, needList[i].FileName+",") {
  416. entity.SupplierTypeCode = "000"
  417. } else {
  418. entity.SupplierTypeCode = dataother.SupplierTypeCode
  419. }
  420. entity.NeedFileType = needList[i].FileName
  421. entity.FileType = 1
  422. entity.EffectDate = time.Now()
  423. entity.CreateBy = this.User.Realname
  424. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  425. entity.SupType = 1
  426. isRepeat := false
  427. for j := 0; j < len(list); j++ {
  428. if list[j].NeedFileType == needList[i].FileName{
  429. isRepeat = true
  430. break
  431. }
  432. }
  433. if isRepeat == true {
  434. continue
  435. }
  436. svc.InsertEntityBytbl(OilSupplierFileName, &entity)
  437. }
  438. }
  439. }
  440. var errinfo ErrorDataInfo
  441. errinfo.Message = "操作成功!"
  442. errinfo.Code = 0
  443. this.Data["json"] = &errinfo
  444. this.ServeJSON()
  445. }
  446. // @Title 新增准入范围
  447. // @Description 新增准入范围
  448. // @Success 200 {object} controllers.Request
  449. // @router /addbusiness [post]
  450. func (this *OilSupplierCertSubController) AddBusiness() {
  451. var model suppliercertsub.OilSupplierCertSub
  452. var err error
  453. var jsonblob = this.Ctx.Input.RequestBody
  454. json.Unmarshal(jsonblob, &model)
  455. model.CreateBy = this.User.Realname
  456. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  457. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  458. var submodel suppliercertsub.OilSupplierCertSub
  459. where_certsub := " SupplierCertId = "+ utils.ToStr(model.SupplierCertId) + " and SupplierTypeCode = 02"
  460. where_certsub += " and SubClassId = '" + utils.ToStr(model.SubClassId) + "'"
  461. has := svc.GetEntityByWhere(OilSupplierCertSubName, where_certsub, &submodel)
  462. if !has{
  463. //添加到准入分类表中
  464. _, err = svc.InsertEntityBytbl(OilSupplierCertSubName, &model)
  465. }else{
  466. model.Id = submodel.Id
  467. }
  468. var supplierCertModel suppliercert.OilSupplierCert
  469. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  470. svcCert.GetEntityById(model.SupplierCertId, &supplierCertModel)
  471. var supplierModel supplier.OilSupplier
  472. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  473. svcSupplier.GetEntityById(model.SupplierCertId, &supplierModel)
  474. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  475. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  476. var needList []supplierfile.FileList
  477. if model.SupplierTypeCode == "01" {
  478. // needList = filesvc.GetGoodsNeedFileList(model.SubClassId)
  479. } else if model.SupplierTypeCode == "02" {
  480. needList = filesvc.GetBasicNeedFileList(model.SubClassId)
  481. } else {
  482. // needList = filesvc.GetTechNeedFileList(model.SubClassId)
  483. }
  484. if supplierCertModel.InStyle == "4" {
  485. var needFile supplierfile.FileList
  486. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  487. needList = append(needList, needFile)
  488. }
  489. if err == nil {
  490. var list []supplierfile.OilSupplierFile
  491. where := "SupplierId = '" + strconv.Itoa(model.SupplierId) + "'"
  492. svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
  493. //三证合一或五证合一不需要的字段
  494. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  495. //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件,"
  496. mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName")
  497. for i := 0; i < len(needList); i++ {
  498. var entity supplierfile.OilSupplierFile
  499. entity.SupplierId = model.SupplierId
  500. //加入对应表OilSupplierCert2File
  501. var cert2File suppliercertsub.OilSupplierCert2File //创建结构体
  502. cert2File.SupplierId = model.SupplierId
  503. cert2File.SupplierCertId = model.SupplierCertId
  504. cert2File.SupplierTypeCode = model.SupplierTypeCode
  505. cert2File.SubClassId= model.SubClassId
  506. cert2File.Code = model.Code
  507. cert2File.Name = model.Name
  508. cert2File.NeedFileType = needList[i].FileName
  509. svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File)
  510. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了
  511. continue
  512. }
  513. if strings.Contains(mustField, needList[i].FileName+",") {
  514. entity.SupplierTypeCode = "000"
  515. } else {
  516. entity.SupplierTypeCode = model.SupplierTypeCode
  517. }
  518. entity.NeedFileType = needList[i].FileName
  519. entity.FileType = 1
  520. entity.EffectDate = time.Now()
  521. entity.CreateBy = this.User.Realname
  522. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  523. entity.SupType = 1
  524. isRepeat := false
  525. for j := 0; j < len(list); j++ {
  526. if list[j].NeedFileType == needList[i].FileName{
  527. isRepeat = true
  528. break
  529. }
  530. }
  531. if isRepeat == true {
  532. continue
  533. }
  534. svc.InsertEntityBytbl(OilSupplierFileName, &entity)
  535. }
  536. }
  537. var errinfo ErrorDataInfo
  538. if err == nil {
  539. errinfo.Message = "操作成功!"
  540. errinfo.Code = 0
  541. errinfo.Item = model.Id
  542. this.Data["json"] = &errinfo
  543. this.ServeJSON()
  544. } else {
  545. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  546. errinfo.Code = -1
  547. this.Data["json"] = &errinfo
  548. this.ServeJSON()
  549. }
  550. }
  551. // @Title 删除准入范围
  552. // @Description
  553. // @Success 200 {object} ErrorInfo
  554. // @Failure 403 :id 为空
  555. // @router /businessdelete/:Id [delete]
  556. func (this *OilSupplierCertSubController) BusinessDelete() {
  557. Id := this.Ctx.Input.Param(":Id")
  558. var errinfo ErrorInfo
  559. if Id == "" {
  560. errinfo.Message = "操作失败!请求信息不完整"
  561. errinfo.Code = -2
  562. this.Data["json"] = &errinfo
  563. this.ServeJSON()
  564. return
  565. }
  566. Ids := strings.Split(Id, ",")
  567. //根据Id查出OilSupplierCertSub的SubClassId
  568. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) //获得数据库引擎
  569. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  570. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  571. for i:=0;i<len(Ids);i++{
  572. var datamain suppliercertsub.OilSupplierCertSub //创建OilSupplierCertSub结构体(映射用)
  573. var datamain2 []suppliercertsub.OilSupplierCertSub //空的查询用
  574. where := " Id= " + Ids[i]
  575. svc.GetEntity(&datamain, where) //根据Id查找,映射结构体
  576. //再根据企业id查找这个企业有几个准入范围(如果只有一个准入范围了,基本资质也删除)
  577. supplierId := datamain.SupplierId
  578. where = "SupplierId=" + strconv.Itoa(supplierId)
  579. svc.GetEntities(&datamain2, where)
  580. flag := 0
  581. if len(datamain2) == 1 {
  582. flag = 1
  583. }
  584. subClassId := datamain.SubClassId //4.拿到结构体中的准入范围SubClassId
  585. //根据SubClassId查出此准入范围所拥有的资质名称
  586. var needList []supplierfile.FileList //定义存储所拥有资质名称的数组
  587. if datamain.SupplierTypeCode == "01" {
  588. needList = filesvc.GetGoodsNeedFileList(strconv.Itoa(subClassId)) //通过准入范围Id获得资质名称并填充数组
  589. } else if datamain.SupplierTypeCode == "02" {
  590. needList = filesvc.GetBasicNeedFileList(subClassId)
  591. } else {
  592. needList = filesvc.GetTechNeedFileList(subClassId)
  593. }
  594. var mustField string
  595. mustField = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName") //必需的资质
  596. //根据企业ID(SupplierId)和此准入范围所拥有的资质名称删除OilSupplierFile表中对应的资质
  597. for j := 0; j < len(needList); j++ { //循环遍历资质名称数组,逐条删除
  598. if flag == 0 && strings.Contains(mustField, needList[j].FileName+",") {
  599. continue
  600. }
  601. where := " SupplierId= '" + strconv.Itoa(datamain.SupplierId) + "' and NeedFileType='" + needList[j].FileName + "'" //拼接删除sql
  602. err := svc.DeleteEntityBytbl(OilSupplierFileName, where) //删除第j条资质数据
  603. if err == nil {
  604. errinfo.Message = "删除成功"
  605. errinfo.Code = 0
  606. this.Data["json"] = &errinfo
  607. this.ServeJSON()
  608. } else {
  609. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  610. errinfo.Code = -1
  611. this.Data["json"] = &errinfo
  612. this.ServeJSON()
  613. }
  614. }
  615. where = " SupplierId=" + strconv.Itoa(datamain.SupplierId) + " and SubClassId=" + strconv.Itoa(subClassId)
  616. err1 := svc.DeleteEntityBytbl(OilSupplierCert2FileName, where)
  617. if err1 == nil {
  618. errinfo.Message = "删除成功"
  619. errinfo.Code = 0
  620. this.Data["json"] = &errinfo
  621. this.ServeJSON()
  622. } else {
  623. errinfo.Message = "删除失败!" + utils.AlertProcess(err1.Error())
  624. errinfo.Code = -1
  625. this.Data["json"] = &errinfo
  626. this.ServeJSON()
  627. }
  628. where = " Id= " + Ids[i]
  629. err2 := svc.DeleteEntityBytbl(OilSupplierCertSubName, where) //删除OilSupplierCertSub单条准入范围
  630. if err2 == nil {
  631. errinfo.Message = "删除成功"
  632. errinfo.Code = 0
  633. this.Data["json"] = &errinfo
  634. this.ServeJSON()
  635. } else {
  636. errinfo.Message = "删除失败!" + utils.AlertProcess(err2.Error())
  637. errinfo.Code = -1
  638. this.Data["json"] = &errinfo
  639. this.ServeJSON()
  640. }
  641. }
  642. }
  643. // @Title 获取待审核业务列表
  644. // @Description get user by token
  645. // @Success 200 {object} models.Userblood
  646. // @router /auditbuslist [get]
  647. func (this *OilSupplierCertSubController) AuditbusList() {
  648. var list []suppliercertsub.OilSupplierCertSub
  649. //获取分页信息
  650. page := this.GetPageInfoForm()
  651. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  652. orderby := "CreateOn desc"
  653. Order := this.GetString("Order")
  654. Prop := this.GetString("Prop")
  655. if Order != "" && Prop != "" {
  656. orderby = Prop + " " + Order
  657. }
  658. where := "1 = 1"
  659. SupplierCertId := this.GetString("SupplierCertId")
  660. if SupplierCertId != "" {
  661. where = where + " and a.SupplierCertId = '" + SupplierCertId + "'"
  662. }
  663. total, list := svc.GetWaitAuditBusinesslist(page.CurrentPage, page.Size, orderby, OilSupplierCertSubName, OilClassOrgSettingName, where)
  664. var datainfo DataInfo
  665. datainfo.Items = list
  666. datainfo.CurrentItemCount = total
  667. this.Data["json"] = &datainfo
  668. this.ServeJSON()
  669. }
  670. // @Title 获取审核意见列表
  671. // @Description 获取审核意见列表
  672. // @Success 200 {object} controllers.Request
  673. // @router /opinionlist [get]
  674. func (this *OilSupplierCertSubController) OpinionList() {
  675. SupplierCertSubId := this.GetString("SupplierCertSubId")
  676. var list []suppliercertsub.OilSupplierOpinion
  677. where := " 1 = 1 "
  678. if SupplierCertSubId != "" {
  679. where = where + " and SupplierCertSubId = '" + SupplierCertSubId + "'"
  680. }
  681. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  682. svc.GetEntitysByWhere(OilSupplierOpinionName, where, &list)
  683. var datainfo DataInfo
  684. datainfo.Items = list
  685. this.Data["json"] = &datainfo
  686. this.ServeJSON()
  687. }
  688. // @Title 新增审核意见
  689. // @Description 新增审核意见
  690. // @Success 200 {object} controllers.Request
  691. // @router /addopinion [post]
  692. func (this *OilSupplierCertSubController) AddOpinion() {
  693. var model suppliercertsub.OilSupplierOpinion
  694. var jsonblob = this.Ctx.Input.RequestBody
  695. json.Unmarshal(jsonblob, &model)
  696. model.AuditorName = this.User.Realname
  697. model.AuditorId, _ = utils.StrTo(this.User.Id).Int()
  698. model.CreateBy = this.User.Realname
  699. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  700. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  701. //where := "SupplierCertSubId=" + strconv.Itoa(model.SupplierCertSubId) + " and AuditorId= " + strconv.Itoa(model.AuditorId) + " and Status = '" + model.Status + "'"
  702. //svc.DeleteEntityBytbl(OilSupplierOpinionName, where)
  703. _, err := svc.InsertEntityBytbl(OilSupplierOpinionName, &model)
  704. var errinfo ErrorDataInfo
  705. if err == nil {
  706. errinfo.Message = "操作成功!"
  707. errinfo.Code = 0
  708. errinfo.Item = model.Id
  709. this.Data["json"] = &errinfo
  710. this.ServeJSON()
  711. } else {
  712. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  713. errinfo.Code = -1
  714. this.Data["json"] = &errinfo
  715. this.ServeJSON()
  716. }
  717. }