suppliercertsub.go 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  1. package oilsupplier
  2. import (
  3. "dashoo.cn/backend/api/business/oilsupplier/goodsaptitudeclass"
  4. "dashoo.cn/backend/api/business/oilsupplier/supplier"
  5. "dashoo.cn/backend/api/business/oilsupplier/suppliercert"
  6. "dashoo.cn/backend/api/business/oilsupplier/suppliercertappendsub"
  7. "dashoo.cn/backend/api/business/oilsupplier/supplierpausereason"
  8. "dashoo.cn/backend/api/business/oilsupplier/tableheader"
  9. "dashoo.cn/backend/api/business/organize"
  10. "dashoo.cn/business2/parameter"
  11. "encoding/json"
  12. //"fmt"
  13. "strconv"
  14. "strings"
  15. "time"
  16. "dashoo.cn/backend/api/business/baseUser"
  17. "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
  18. "dashoo.cn/backend/api/business/oilsupplier/supplierfile"
  19. // "dashoo.cn/backend/api/business/oilsupplier/technologyservice"
  20. . "dashoo.cn/backend/api/controllers"
  21. "dashoo.cn/business2/userRole"
  22. "dashoo.cn/utils"
  23. )
  24. type OilSupplierCertSubController struct {
  25. BaseController
  26. }
  27. // @Title 获取列表
  28. // @Description get user by token
  29. // @Success 200 {object} []suppliercertsub.OilSupplierCertSub
  30. // @router /list [get]
  31. func (this *OilSupplierCertSubController) GetEntityList() {
  32. //获取分页信息
  33. page := this.GetPageInfoForm()
  34. where := " 1=1 "
  35. orderby := "CertSubStatus, Code"
  36. asc := false
  37. Order := this.GetString("Order")
  38. Prop := this.GetString("Prop")
  39. if Order != "" && Prop != "" {
  40. orderby = Prop
  41. if Order == "asc" {
  42. asc = true
  43. }
  44. }
  45. Id := this.GetString("Id")
  46. SupplierId := this.GetString("SupplierId")
  47. SupplierCertId := this.GetString("SupplierCertId")
  48. SupplierTypeCode := this.GetString("SupplierTypeCode")
  49. Code := this.GetString("Code")
  50. Name := this.GetString("Name")
  51. Remark := this.GetString("Remark")
  52. IsDelete := this.GetString("IsDelete")
  53. CreateOn := this.GetString("CreateOn")
  54. CreateUserId := this.GetString("CreateUserId")
  55. CreateBy := this.GetString("CreateBy")
  56. ModifiedOn := this.GetString("ModifiedOn")
  57. ModifiedUserId := this.GetString("ModifiedUserId")
  58. ModifiedBy := this.GetString("ModifiedBy")
  59. if Id != "" {
  60. where = where + " and Id like '%" + Id + "%'"
  61. }
  62. if SupplierId != "" {
  63. where = where + " and SupplierId like '%" + SupplierId + "%'"
  64. }
  65. if SupplierCertId != "" {
  66. where = where + " and SupplierCertId = '" + SupplierCertId + "'"
  67. }
  68. if SupplierTypeCode != "" {
  69. where = where + " and SupplierTypeCode = '" + SupplierTypeCode + "'"
  70. }
  71. if Code != "" {
  72. where = where + " and Code like '" + Code + "%'"
  73. }
  74. if Name != "" {
  75. where = where + " and Name like '%" + Name + "%'"
  76. }
  77. if Remark != "" {
  78. where = where + " and Remark like '%" + Remark + "%'"
  79. }
  80. if IsDelete != "" {
  81. where = where + " and IsDelete like '%" + IsDelete + "%'"
  82. }
  83. if CreateUserId != "" {
  84. where = where + " and CreateUserId like '%" + CreateUserId + "%'"
  85. }
  86. if CreateBy != "" {
  87. where = where + " and CreateBy like '%" + CreateBy + "%'"
  88. }
  89. if ModifiedOn != "" {
  90. where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
  91. }
  92. if ModifiedUserId != "" {
  93. where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
  94. }
  95. if ModifiedBy != "" {
  96. where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
  97. }
  98. if CreateOn != "" {
  99. dates := strings.Split(CreateOn, ",")
  100. if len(dates) == 2 {
  101. minDate := dates[0]
  102. maxDate := dates[1]
  103. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  104. }
  105. }
  106. where = where + " and Type in (1, 3)"
  107. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  108. var list []suppliercertsub.OilSupplierCertSub
  109. total := svc.GetPagingEntitiesWithoutAccCode(page.CurrentPage, page.Size, orderby, asc, &list, where)
  110. var datainfo DataInfo
  111. datainfo.Items = list
  112. datainfo.CurrentItemCount = total
  113. datainfo.PageIndex = page.CurrentPage
  114. datainfo.ItemsPerPage = page.Size
  115. this.Data["json"] = &datainfo
  116. this.ServeJSON()
  117. }
  118. // @Title 获取列表
  119. // @Description
  120. // @Success 200 {object}
  121. // @router /listCert2019 [get]
  122. func (this *OilSupplierCertSubController) ListCert2019() {
  123. //获取分页信息
  124. page := this.GetPageInfoForm()
  125. where := " 1=1 "
  126. orderby := "Id"
  127. asc := true
  128. Order := this.GetString("Order")
  129. Prop := this.GetString("Prop")
  130. if Order != "" && Prop != "" {
  131. orderby = Prop
  132. if Order == "asc" {
  133. asc = true
  134. }
  135. }
  136. Name := this.GetString("Name")
  137. if Name != "" {
  138. where = where + " and (Name like '%" + Name + "%' or Code like '%" + Name + "%')"
  139. }
  140. where = where + " and Edition = '2'"
  141. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  142. var list []goodsaptitudeclass.OilGoodsAptitudeClass
  143. total := svc.GetPagingEntitiesWithoutAccCode(page.CurrentPage, page.Size, orderby, asc, &list, where)
  144. var datainfo DataInfo
  145. datainfo.Items = list
  146. datainfo.CurrentItemCount = total
  147. this.Data["json"] = &datainfo
  148. this.ServeJSON()
  149. }
  150. // @Title 获取字典列表
  151. // @Description get user by token
  152. // @Success 200 {object} map[string]interface{}
  153. // @router /dictlist [get]
  154. func (this *OilSupplierCertSubController) GetDictList() {
  155. dictList := make(map[string]interface{})
  156. //dictSvc := items.GetItemsService(utils.DBE)
  157. userSvc := baseUser.GetBaseUserService(utils.DBE)
  158. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  159. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", this.User.AccCode)
  160. var userEntity userRole.Base_User
  161. userSvc.GetEntityById(this.User.Id, &userEntity)
  162. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId(this.User.AccCode, userEntity.Departmentid)
  163. //var dictCustomer []svccustomer.Customer
  164. //customerSvc.GetEntitysByWhere(this.User.AccCode + CustomerName, "", &dictCustomer)
  165. //dictList["EntrustCorp"] = &dictCustomer
  166. var datainfo DataInfo
  167. datainfo.Items = dictList
  168. this.Data["json"] = &datainfo
  169. this.ServeJSON()
  170. }
  171. // @Title 获取实体
  172. // @Description 获取实体
  173. // @Success 200 {object} suppliercertsub.OilSupplierCertSub
  174. // @router /get/:id [get]
  175. func (this *OilSupplierCertSubController) GetEntity() {
  176. Id := this.Ctx.Input.Param(":id")
  177. var model suppliercertsub.OilSupplierCertSub
  178. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  179. svc.GetEntityByIdBytbl(OilSupplierCertSubName, Id, &model)
  180. this.Data["json"] = &model
  181. this.ServeJSON()
  182. }
  183. // @Title 添加
  184. // @Description 新增
  185. // @Success 200 {object} controllers.Request
  186. // @router /add [post]
  187. func (this *OilSupplierCertSubController) AddEntity() {
  188. var model suppliercertsub.OilSupplierCertSub
  189. var jsonBlob = this.Ctx.Input.RequestBody
  190. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  191. json.Unmarshal(jsonBlob, &model)
  192. model.CreateOn = time.Now()
  193. model.CreateBy = this.User.Realname
  194. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  195. //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  196. _, err := svc.InsertEntityBytbl(OilSupplierCertSubName, &model)
  197. var errinfo ErrorDataInfo
  198. if err == nil {
  199. //新增
  200. errinfo.Message = "添加成功!"
  201. errinfo.Code = 0
  202. errinfo.Item = model.Id
  203. this.Data["json"] = &errinfo
  204. this.ServeJSON()
  205. } else {
  206. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  207. errinfo.Code = -1
  208. this.Data["json"] = &errinfo
  209. this.ServeJSON()
  210. }
  211. }
  212. // @Title 修改实体
  213. // @Description 修改实体
  214. // @Success 200 {object} controllers.Request
  215. // @router /update/:id [post]
  216. func (this *OilSupplierCertSubController) UpdateEntity() {
  217. id := this.Ctx.Input.Param(":id")
  218. var errinfo ErrorInfo
  219. if id == "" {
  220. errinfo.Message = "操作失败!请求信息不完整"
  221. errinfo.Code = -2
  222. this.Data["json"] = &errinfo
  223. this.ServeJSON()
  224. return
  225. }
  226. var model suppliercertsub.OilSupplierCertSub
  227. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  228. var jsonBlob = this.Ctx.Input.RequestBody
  229. json.Unmarshal(jsonBlob, &model)
  230. model.ModifiedOn = time.Now()
  231. model.ModifiedBy = this.User.Realname
  232. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  233. cols := []string{
  234. "Id",
  235. "SupplierId",
  236. "SupplierCertId",
  237. "SubClassId",
  238. "Code",
  239. "Name",
  240. "Remark",
  241. "IsDelete",
  242. "CreateOn",
  243. "CreateUserId",
  244. "CreateBy",
  245. "ModifiedOn",
  246. "ModifiedUserId",
  247. "ModifiedBy",
  248. }
  249. err := svc.UpdateEntityBytbl(OilSupplierCertSubName, id, &model, cols)
  250. if err == nil {
  251. errinfo.Message = "修改成功!"
  252. errinfo.Code = 0
  253. this.Data["json"] = &errinfo
  254. this.ServeJSON()
  255. } else {
  256. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  257. errinfo.Code = -1
  258. this.Data["json"] = &errinfo
  259. this.ServeJSON()
  260. }
  261. }
  262. // @Title 删除单条信息
  263. // @Description
  264. // @Success 200 {object} ErrorInfo
  265. // @Failure 403 :id 为空
  266. // @router /delete/:Id [delete]
  267. func (this *OilSupplierCertSubController) DeleteEntity() {
  268. Id := this.Ctx.Input.Param(":Id")
  269. var errinfo ErrorInfo
  270. if Id == "" {
  271. errinfo.Message = "操作失败!请求信息不完整"
  272. errinfo.Code = -2
  273. this.Data["json"] = &errinfo
  274. this.ServeJSON()
  275. return
  276. }
  277. var model suppliercertsub.OilSupplierCertSub
  278. var entityempty suppliercertsub.OilSupplierCertSub
  279. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  280. opdesc := "删除-" + Id
  281. err := svc.DeleteOperationAndWriteLogBytbl(OilSupplierCertSubName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报")
  282. if err == nil {
  283. errinfo.Message = "删除成功"
  284. errinfo.Code = 0
  285. this.Data["json"] = &errinfo
  286. this.ServeJSON()
  287. } else {
  288. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  289. errinfo.Code = -1
  290. this.Data["json"] = &errinfo
  291. this.ServeJSON()
  292. }
  293. }
  294. // @Title 批量添加准入范围--物资类
  295. // @Description 批量添加准入范围
  296. // @Success 200 {object} business.device.DeviceChannels
  297. // @router /check-certsub-lost [post]
  298. func (this *OilSupplierCertSubController) CheckCertSubLost () {
  299. var jsonblob = this.Ctx.Input.RequestBody
  300. var datamain suppliercertsub.OilSupplierCertSub
  301. var dataother suppliercertsub.SupplierCertSubModel
  302. json.Unmarshal(jsonblob, &datamain)
  303. json.Unmarshal(jsonblob, &dataother)
  304. var supplierCertModel suppliercert.OilSupplierCert
  305. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  306. svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel)
  307. var lostCertList []LostCertFiles
  308. // 查询出已有哪些资质
  309. supplierId := dataother.SupplierId
  310. supplierTypeCode := dataother.SupplierTypeCode
  311. var tableheaderList []supplierfile.OilSupplierFile
  312. fileSql := "SELECT * from OilSupplierFile WHERE SupplierId='" + strconv.Itoa(supplierId) + "'"
  313. fileSql += " AND (SupplierTypeCode='" + supplierTypeCode + "' or SupplierTypeCode='000')"
  314. svcHeader := tableheader.GetTableHeaderService(utils.DBE)
  315. svcHeader.DBE.SQL(fileSql).Find(&tableheaderList)
  316. var companyHasHeaders string
  317. for _, tableheader := range tableheaderList {
  318. companyHasHeaders += tableheader.NeedFileType + ","
  319. }
  320. var supplierModel supplier.OilSupplier
  321. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  322. svcSupplier.GetEntityById(datamain.SupplierId, &supplierModel)
  323. //逐条检查需要的资质
  324. for n := 0; n < len(dataother.CheckList); n++ {
  325. if supplierModel.OperType == "制造商" {
  326. datamain.IsManufacturer = 1
  327. } else {
  328. datamain.IsManufacturer = 2
  329. }
  330. //检查是否资质全面
  331. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  332. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  333. needList := filesvc.GetGoodsNeedFileList(dataother.CheckList[n].Id, strconv.Itoa(datamain.IsManufacturer)) // 需要的资质
  334. //三证合一或五证合一不需要的字段
  335. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  336. if supplierCertModel.InStyle == "4" {
  337. var needFile supplierfile.FileList
  338. //战略合作协议扫描件
  339. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  340. needList = append(needList, needFile)
  341. }
  342. if datamain.IsManufacturer == 1 { //制造商
  343. var needFile supplierfile.FileList
  344. // 中油集团公司产品质量认可证书
  345. CNPCrenkezhengshu := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CNPCrenkezhengshu")
  346. needFile.FileName = CNPCrenkezhengshu
  347. needList = append(needList, needFile)
  348. }
  349. for _, needHeader := range needList {
  350. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") &&
  351. strings.Contains(mergerCertSkipField, needHeader.FileName+",") {
  352. //三证合一或五证合一的证件,不需要验证了
  353. continue
  354. }
  355. var fileist1 supplierfile.OilSupplierFile
  356. where1 := " SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "' and NeedFileType = '" + needHeader.FileName + "'"
  357. filesvc.GetEntityByWhere(OilSupplierFileName, where1, &fileist1)
  358. var filelist2 suppliercertappendsub.OilAppendChangeDetail
  359. where2 := " SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "' and NeedFileType = '" +needHeader.FileName + "'"
  360. svc2 := suppliercertappendsub.GetOilSupplierCertAppendSubService (utils.DBE)
  361. svc2.GetEntityByWhere(OilAppendChangeDetailName, where2, &filelist2)
  362. if !strings.Contains(companyHasHeaders, needHeader.FileName+",") {
  363. var tmpLostCert LostCertFiles
  364. tmpLostCert.Code = dataother.CheckList[n].Code
  365. tmpLostCert.Name = dataother.CheckList[n].Name
  366. tmpLostCert.CertFileName = needHeader.FileName
  367. lostCertList = append(lostCertList, tmpLostCert)
  368. } else {
  369. if filelist2.FileName == "" && fileist1.FileName == "" {
  370. //缺少的资质
  371. var tmpLostCert LostCertFiles
  372. tmpLostCert.Code = dataother.CheckList[n].Code
  373. tmpLostCert.Name = dataother.CheckList[n].Name
  374. tmpLostCert.CertFileName = needHeader.FileName
  375. lostCertList = append(lostCertList, tmpLostCert)
  376. }
  377. }
  378. }
  379. }
  380. var errinfo ErrorDataInfo
  381. if len(lostCertList) <= 0 {
  382. errinfo.Code = 0
  383. errinfo.Message = "验证通过!"
  384. this.Data["json"] = nil
  385. } else {
  386. errinfo.Code = -1
  387. errinfo.Message = "缺少资质!"
  388. this.Data["json"] = &lostCertList
  389. }
  390. this.ServeJSON()
  391. }
  392. // @Title 批量添加准入范围--物资类
  393. // @Description 批量添加准入范围
  394. // @Success 200 {object} business.device.DeviceChannels
  395. // @router /add-goods-certsub-filter [post]
  396. func (this *OilSupplierCertSubController) AddGoodsByFilter() {
  397. var jsonblob = this.Ctx.Input.RequestBody
  398. var datamain suppliercertsub.OilSupplierCertSub
  399. var dataother suppliercertsub.SupplierCertSubModel
  400. json.Unmarshal(jsonblob, &datamain)
  401. json.Unmarshal(jsonblob, &dataother)
  402. var supplierCertModel suppliercert.OilSupplierCert
  403. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  404. svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel)
  405. // 查询出已有哪些资质
  406. supplierId := dataother.SupplierId
  407. supplierTypeCode := dataother.SupplierTypeCode
  408. var tableheaderList []supplierfile.OilSupplierFile
  409. fileSql := "SELECT * from OilSupplierFile WHERE SupplierId='" + strconv.Itoa(supplierId) + "'"
  410. fileSql += " AND (SupplierTypeCode='" + supplierTypeCode + "' or SupplierTypeCode='000')"
  411. svcHeader := tableheader.GetTableHeaderService(utils.DBE)
  412. svcHeader.DBE.SQL(fileSql).Find(&tableheaderList)
  413. var companyHasHeaders string
  414. for _, tableheader := range tableheaderList {
  415. companyHasHeaders += tableheader.NeedFileType + ","
  416. }
  417. var supplierModel supplier.OilSupplier
  418. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  419. svcSupplier.GetEntityById(datamain.SupplierId, &supplierModel)
  420. // 记录缺少的证件
  421. invalidCertMsg := ""
  422. // 记录保存条数
  423. vaildCnt := 0
  424. //逐条检查需要的资质,符合才会保存
  425. for n := 0; n < len(dataother.CheckList); n++ {
  426. where_sub := "SupplierTypeCode = 01 and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  427. where_sub += " and SupplierCertId = '" + strconv.Itoa(dataother.SupplierCertId) + "'"
  428. where_sub += " and SubClassId = '" + dataother.CheckList[n].Id + "'"
  429. var model suppliercertsub.OilSupplierCertSub
  430. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  431. has := svc.GetEntityByWhere(OilSupplierCertSubName, where_sub, &model)
  432. if !has {
  433. if supplierModel.OperType == "制造商" {
  434. datamain.IsManufacturer = 1
  435. } else {
  436. datamain.IsManufacturer = 2
  437. }
  438. //检查是否资质全面
  439. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  440. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  441. needList := filesvc.GetGoodsNeedFileList(dataother.CheckList[n].Id, strconv.Itoa(datamain.IsManufacturer)) // 需要的资质
  442. //三证合一或五证合一不需要的字段
  443. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  444. if supplierCertModel.InStyle == "4" {
  445. var needFile supplierfile.FileList
  446. //战略合作协议扫描件
  447. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  448. needList = append(needList, needFile)
  449. }
  450. if datamain.IsManufacturer == 1 { //制造商
  451. var needFile supplierfile.FileList
  452. // 中油集团公司产品质量认可证书
  453. CNPCrenkezhengshu := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CNPCrenkezhengshu")
  454. needFile.FileName = CNPCrenkezhengshu
  455. needList = append(needList, needFile)
  456. }
  457. certsValid := true
  458. for _, needHeader := range needList {
  459. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") &&
  460. strings.Contains(mergerCertSkipField, needHeader.FileName+",") {
  461. //三证合一或五证合一的证件,不需要验证了
  462. continue
  463. }
  464. if !strings.Contains(companyHasHeaders, needHeader.FileName+",") {
  465. //缺少资质,不会保存
  466. invalidCertMsg += dataother.CheckList[n].Code + " " + dataother.CheckList[n].Name + "(缺少:" + needHeader.FileName + ") ,"
  467. certsValid = false
  468. break
  469. }
  470. }
  471. if !certsValid {
  472. //缺少资质,不会保存
  473. continue
  474. }
  475. datamain.SubClassId, _ = utils.StrTo(dataother.CheckList[n].Id).Int()
  476. datamain.Code = dataother.CheckList[n].Code
  477. datamain.Name = dataother.CheckList[n].Name
  478. datamain.GoodsLevel = dataother.CheckList[n].GoodsLevel
  479. datamain.Remark = dataother.Remark
  480. datamain.IsDelete = 0
  481. datamain.CreateBy = this.User.Realname
  482. datamain.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  483. unitsvc := organize.GetOrganizeService(utils.DBE)
  484. unitid := unitsvc.GetMyUnitDepartmentId(this.User.DepartmentId)
  485. if unitid == "100000650" { // 100000650 企管法规处(内控与风险管理处)
  486. datamain.CertSubStatus = "1"
  487. }
  488. datamain.Id = 0
  489. //插入准入范围表
  490. svc.InsertEntityBytbl(OilSupplierCertSubName, &datamain)
  491. // TODO: 删除准入范围和资质对应关系表
  492. //插入准入范围所需资质记录表
  493. /*for _, needHeader := range needList {
  494. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") &&
  495. strings.Contains(mergerCertSkipField, needHeader.FileName+",") {
  496. //三证合一或五证合一的证件,不需要保存
  497. continue
  498. }
  499. //加入对应表OilSupplierCert2File, 保存准入项所需的资质关系
  500. var cert2File suppliercertsub.OilSupplierCert2File //创建结构体
  501. cert2File.SupplierId = dataother.SupplierId
  502. cert2File.SupplierCertId = dataother.SupplierCertId
  503. cert2File.SupplierCertSubId = datamain.Id
  504. cert2File.SupplierTypeCode = dataother.SupplierTypeCode
  505. cert2File.IsManuf = strconv.Itoa(datamain.IsManufacturer)
  506. cert2File.SubClassId, _ = utils.StrTo(dataother.CheckList[n].Id).Int()
  507. cert2File.Code = dataother.CheckList[n].Code
  508. cert2File.Name = dataother.CheckList[n].Name
  509. cert2File.NeedFileType = needHeader.FileName
  510. svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File)
  511. }*/
  512. vaildCnt++
  513. }
  514. }
  515. var errinfo ErrorDataInfo
  516. if invalidCertMsg == "" {
  517. errinfo.Code = 0
  518. errinfo.Message = "操作成功!"
  519. } else if vaildCnt > 0 {
  520. errinfo.Code = -1
  521. errinfo.Message = "部分成功!" + invalidCertMsg
  522. } else {
  523. errinfo.Message = invalidCertMsg
  524. }
  525. this.Data["json"] = &errinfo
  526. this.ServeJSON()
  527. }
  528. // @Title 批量添加准入范围--技术服务类
  529. // @Description 批量添加准入范围
  530. // @Success 200 {object} business.device.DeviceChannels
  531. // @router /tech-cert-lost [post]
  532. func (this *OilSupplierCertSubController) CheckTechCertLost() {
  533. var jsonblob = this.Ctx.Input.RequestBody
  534. var datamain suppliercertsub.OilSupplierCertSub
  535. var dataother suppliercertsub.TechnologySubModel
  536. json.Unmarshal(jsonblob, &datamain)
  537. json.Unmarshal(jsonblob, &dataother)
  538. var supplierCertModel suppliercert.OilSupplierCert
  539. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  540. svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel)
  541. var supplierModel supplier.OilSupplier
  542. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  543. svcSupplier.GetEntityById(datamain.SupplierId, &supplierModel)
  544. var lostCertList []LostCertFiles
  545. for n := 0; n < len(dataother.CheckList); n++ {
  546. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  547. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  548. needList := filesvc.GetTechNeedFileList(strconv.Itoa(dataother.CheckList[n].Id))
  549. if supplierCertModel.InStyle == "4" {
  550. var needFile supplierfile.FileList
  551. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  552. needList = append(needList, needFile)
  553. }
  554. var fileist []supplierfile.OilSupplierFile
  555. where := "SupplierTypeCode in ('03','000') and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  556. svcSupplier.GetEntitysByWhere(OilSupplierFileName, where, &fileist)
  557. var companyHasHeaders string
  558. for _, tableheader := range fileist {
  559. companyHasHeaders += tableheader.NeedFileType + ","
  560. }
  561. //三证合一或五证合一不需要的字段
  562. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  563. for i := 0; i < len(needList); i++ {
  564. var entity supplierfile.OilSupplierFile
  565. entity.SupplierId = dataother.SupplierId
  566. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了
  567. continue
  568. }
  569. var fileist1 supplierfile.OilSupplierFile
  570. where1 := " SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "' and NeedFileType = '" + needList[i].FileName + "'"
  571. filesvc.GetEntityByWhere(OilSupplierFileName, where1, &fileist1)
  572. var filelist2 suppliercertappendsub.OilAppendChangeDetail
  573. where2 := " SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "' and NeedFileType = '" + needList[i].FileName + "'"
  574. svc2 := suppliercertappendsub.GetOilSupplierCertAppendSubService (utils.DBE)
  575. svc2.GetEntityByWhere(OilAppendChangeDetailName, where2, &filelist2)
  576. if !strings.Contains(companyHasHeaders, needList[i].FileName+",") {
  577. var tmpLostCert LostCertFiles
  578. tmpLostCert.Code = dataother.CheckList[n].Code
  579. tmpLostCert.Name = dataother.CheckList[n].Name
  580. tmpLostCert.CertFileName = needList[i].FileName
  581. lostCertList = append(lostCertList, tmpLostCert)
  582. } else {
  583. if filelist2.FileName == "" && fileist1.FileName == "" {
  584. //缺少的资质
  585. var tmpLostCert LostCertFiles
  586. tmpLostCert.Code = dataother.CheckList[n].Code
  587. tmpLostCert.Name = dataother.CheckList[n].Name
  588. tmpLostCert.CertFileName = needList[i].FileName
  589. lostCertList = append(lostCertList, tmpLostCert)
  590. }
  591. }
  592. }
  593. }
  594. var errinfo ErrorDataInfo
  595. if len(lostCertList) <= 0 {
  596. errinfo.Code = 0
  597. errinfo.Message = "验证通过!"
  598. this.Data["json"] = nil
  599. } else {
  600. errinfo.Code = -1
  601. errinfo.Message = "缺少资质!"
  602. this.Data["json"] = &lostCertList
  603. }
  604. this.ServeJSON()
  605. }
  606. // @Title 批量添加准入范围--技术服务类
  607. // @Description 批量添加准入范围
  608. // @Success 200 {object} business.device.DeviceChannels
  609. // @router /addtechbus [post]
  610. func (this *OilSupplierCertSubController) AddTechBus() {
  611. //TODO: 没有像AddGoodsByFilter一样,保存时做合法性验证,因为在保存之前已经在前台调用了CheckTechCertLost验证过了,
  612. // 以后有时间再加上
  613. var jsonblob = this.Ctx.Input.RequestBody
  614. var datamain suppliercertsub.OilSupplierCertSub
  615. var dataother suppliercertsub.TechnologySubModel
  616. json.Unmarshal(jsonblob, &datamain)
  617. json.Unmarshal(jsonblob, &dataother)
  618. var supplierCertModel suppliercert.OilSupplierCert
  619. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  620. svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel)
  621. var supplierModel supplier.OilSupplier
  622. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  623. svcSupplier.GetEntityById(datamain.SupplierId, &supplierModel)
  624. for n := 0; n < len(dataother.CheckList); n++ {
  625. where_sub := "SupplierTypeCode = 03 and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  626. where_sub += " and SupplierCertId = '" + strconv.Itoa(dataother.SupplierCertId) + "'"
  627. where_sub += " and SubClassId = '" + strconv.Itoa(dataother.CheckList[n].Id) + "'"
  628. var model suppliercertsub.OilSupplierCertSub
  629. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  630. has := svc.GetEntityByWhere(OilSupplierCertSubName, where_sub, &model)
  631. if !has {
  632. datamain.SubClassId = dataother.CheckList[n].Id
  633. datamain.Code = dataother.CheckList[n].Code
  634. datamain.Name = dataother.CheckList[n].Name
  635. datamain.Remark = dataother.Remark
  636. datamain.IsDelete = 0
  637. datamain.CreateBy = this.User.Realname
  638. datamain.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  639. unitsvc := organize.GetOrganizeService(utils.DBE)
  640. unitid := unitsvc.GetMyUnitDepartmentId(this.User.DepartmentId)
  641. if unitid == "100000650" {
  642. datamain.CertSubStatus = "1"
  643. }
  644. datamain.Id = 0
  645. svc.InsertEntityBytbl(OilSupplierCertSubName, &datamain)
  646. // TODO: 删除准入范围和资质对应关系表
  647. /*paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  648. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  649. needList := filesvc.GetTechNeedFileList(strconv.Itoa(dataother.CheckList[n].Id))
  650. if supplierCertModel.InStyle == "4" {
  651. var needFile supplierfile.FileList
  652. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  653. needList = append(needList, needFile)
  654. }
  655. var list []supplierfile.OilSupplierFile
  656. where := "SupplierTypeCode in (03,000) and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  657. svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
  658. //三证合一或五证合一不需要的字段
  659. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  660. // "营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件,"
  661. // mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName")
  662. for i := 0; i < len(needList); i++ {
  663. var entity supplierfile.OilSupplierFile
  664. entity.SupplierId = dataother.SupplierId
  665. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了
  666. continue
  667. }
  668. //加入对应表OilSupplierCert2File
  669. var cert2File suppliercertsub.OilSupplierCert2File //创建结构体
  670. cert2File.SupplierId = dataother.SupplierId
  671. cert2File.SupplierCertId = dataother.SupplierCertId
  672. cert2File.SupplierCertSubId = datamain.Id
  673. cert2File.SupplierTypeCode = dataother.SupplierTypeCode
  674. cert2File.SubClassId = dataother.CheckList[n].Id
  675. cert2File.Code = dataother.CheckList[n].Code
  676. cert2File.Name = dataother.CheckList[n].Name
  677. cert2File.NeedFileType = needList[i].FileName
  678. svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File)
  679. }*/
  680. }
  681. }
  682. var errinfo ErrorDataInfo
  683. errinfo.Message = "操作成功!"
  684. errinfo.Code = 0
  685. this.Data["json"] = &errinfo
  686. this.ServeJSON()
  687. }
  688. // @Title 检查资质是否完整--基建类
  689. // @Description 批量添加准入范围
  690. // @Success 200 {object} lostCertList []LostCertFiles
  691. // @router /check-basis-lost [post]
  692. func (this *OilSupplierCertSubController) CheckBasisBusinessLost() {
  693. var model suppliercertsub.OilSupplierCertSub
  694. var err error
  695. var jsonblob = this.Ctx.Input.RequestBody
  696. json.Unmarshal(jsonblob, &model)
  697. var supplierCertModel suppliercert.OilSupplierCert
  698. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  699. svcCert.GetEntityById(model.SupplierCertId, &supplierCertModel)
  700. var supplierModel supplier.OilSupplier
  701. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  702. svcSupplier.GetEntityById(model.SupplierId, &supplierModel)
  703. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  704. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  705. var needList []supplierfile.FileList
  706. var lostCertList []LostCertFiles
  707. needList = filesvc.GetBasicNeedFileList(strconv.Itoa(model.SubClassId))
  708. if supplierCertModel.InStyle == "4" {
  709. var needFile supplierfile.FileList
  710. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  711. needList = append(needList, needFile)
  712. }
  713. if err == nil {
  714. var list []supplierfile.OilSupplierFile
  715. where := "SupplierTypeCode in (02,000) and SupplierId = '" + strconv.Itoa(model.SupplierId) + "'"
  716. svcCert.GetEntitysByWhere(OilSupplierFileName, where, &list)
  717. var companyHasHeaders string
  718. for _, tableheader := range list {
  719. companyHasHeaders += tableheader.NeedFileType + ","
  720. }
  721. //三证合一或五证合一不需要的字段
  722. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  723. //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件,"
  724. // mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName")
  725. for i := 0; i < len(needList); i++ {
  726. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了
  727. continue
  728. }
  729. var fileist1 supplierfile.OilSupplierFile
  730. where1 := " SupplierId = '" + strconv.Itoa(model.SupplierId) + "' and NeedFileType = '" + needList[i].FileName + "'"
  731. filesvc.GetEntityByWhere(OilSupplierFileName, where1, &fileist1)
  732. var filelist2 suppliercertappendsub.OilAppendChangeDetail
  733. where2 := " SupplierId = '" + strconv.Itoa(model.SupplierId) + "' and NeedFileType = '" + needList[i].FileName + "'"
  734. svc2 := suppliercertappendsub.GetOilSupplierCertAppendSubService (utils.DBE)
  735. svc2.GetEntityByWhere(OilAppendChangeDetailName, where2, &filelist2)
  736. if !strings.Contains(companyHasHeaders, needList[i].FileName+",") {
  737. var tmpLostCert LostCertFiles
  738. tmpLostCert.Code = model.Code
  739. tmpLostCert.Name = model.Name
  740. tmpLostCert.CertFileName = needList[i].FileName
  741. lostCertList = append(lostCertList, tmpLostCert)
  742. } else {
  743. if filelist2.FileName == "" && fileist1.FileName == "" {
  744. //缺少的资质
  745. var tmpLostCert LostCertFiles
  746. tmpLostCert.Code = model.Code
  747. tmpLostCert.Name = model.Name
  748. tmpLostCert.CertFileName = needList[i].FileName
  749. lostCertList = append(lostCertList, tmpLostCert)
  750. }
  751. }
  752. }
  753. }
  754. var errinfo ErrorDataInfo
  755. if len(lostCertList) <= 0 {
  756. errinfo.Code = 0
  757. errinfo.Message = "验证通过!"
  758. this.Data["json"] = nil
  759. } else {
  760. errinfo.Code = -1
  761. errinfo.Message = "缺少资质!"
  762. this.Data["json"] = &lostCertList
  763. }
  764. this.ServeJSON()
  765. }
  766. // @Title 新增准入范围 --基建类
  767. // @Description 新增准入范围 --基建类
  768. // @Success 200 {object} controllers.Request
  769. // @router /addbusiness [post]
  770. func (this *OilSupplierCertSubController) AddBusiness() {
  771. var model suppliercertsub.OilSupplierCertSub
  772. var err error
  773. var jsonblob = this.Ctx.Input.RequestBody
  774. json.Unmarshal(jsonblob, &model)
  775. model.CreateBy = this.User.Realname
  776. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  777. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  778. var submodel suppliercertsub.OilSupplierCertSub
  779. where_certsub := " SupplierCertId = " + utils.ToStr(model.SupplierCertId) + " and SupplierTypeCode = 02"
  780. where_certsub += " and SubClassId = '" + utils.ToStr(model.SubClassId) + "'"
  781. has := svc.GetEntityByWhere(OilSupplierCertSubName, where_certsub, &submodel)
  782. unitsvc := organize.GetOrganizeService(utils.DBE)
  783. unitid := unitsvc.GetMyUnitDepartmentId(this.User.DepartmentId)
  784. if !has {
  785. //添加到准入分类表中
  786. if unitid == "100000095" {
  787. model.CertSubStatus = "1"
  788. }
  789. _, err = svc.InsertEntityBytbl(OilSupplierCertSubName, &model)
  790. } else {
  791. model.Id = submodel.Id
  792. }
  793. // TODO: 删除准入范围和资质对应关系表
  794. /* var supplierCertModel suppliercert.OilSupplierCert
  795. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  796. svcCert.GetEntityById(model.SupplierCertId, &supplierCertModel)
  797. var supplierModel supplier.OilSupplier
  798. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  799. svcSupplier.GetEntityById(model.SupplierId, &supplierModel)
  800. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  801. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  802. var needList []supplierfile.FileList
  803. if model.SupplierTypeCode == "01" {
  804. // needList = filesvc.GetGoodsNeedFileList(model.SubClassId)
  805. } else if model.SupplierTypeCode == "02" {
  806. needList = filesvc.GetBasicNeedFileList(strconv.Itoa(model.SubClassId))
  807. } else {
  808. // needList = filesvc.GetTechNeedFileList(model.SubClassId)
  809. }
  810. if supplierCertModel.InStyle == "4" {
  811. var needFile supplierfile.FileList
  812. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  813. needList = append(needList, needFile)
  814. }
  815. if err == nil {
  816. var list []supplierfile.OilSupplierFile
  817. where := "SupplierTypeCode in (02,000) and SupplierId = '" + strconv.Itoa(model.SupplierId) + "'"
  818. svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
  819. //三证合一或五证合一不需要的字段
  820. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  821. //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件,"
  822. // mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName")
  823. for i := 0; i < len(needList); i++ {
  824. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了
  825. continue
  826. }
  827. var entity supplierfile.OilSupplierFile
  828. entity.SupplierId = model.SupplierId
  829. //加入对应表OilSupplierCert2File
  830. var cert2File suppliercertsub.OilSupplierCert2File //创建结构体
  831. cert2File.SupplierId = model.SupplierId
  832. cert2File.SupplierCertId = model.SupplierCertId
  833. cert2File.SupplierCertSubId = model.Id
  834. cert2File.SupplierTypeCode = model.SupplierTypeCode
  835. cert2File.SubClassId = model.SubClassId
  836. cert2File.Code = model.Code
  837. cert2File.Name = model.Name
  838. cert2File.NeedFileType = needList[i].FileName
  839. svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File)
  840. }
  841. }*/
  842. var errinfo ErrorDataInfo
  843. if err == nil {
  844. errinfo.Message = "操作成功!"
  845. errinfo.Code = 0
  846. errinfo.Item = model.Id
  847. this.Data["json"] = &errinfo
  848. this.ServeJSON()
  849. } else {
  850. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  851. errinfo.Code = -1
  852. this.Data["json"] = &errinfo
  853. this.ServeJSON()
  854. }
  855. }
  856. // @Title 删除准入范围
  857. // @Description
  858. // @Success 200 {object} ErrorInfo
  859. // @Failure 403 :id 为空
  860. // @router /businessdelete/:Id [delete]
  861. func (this *OilSupplierCertSubController) BusinessDelete() {
  862. Id := this.Ctx.Input.Param(":Id")
  863. //SupplierCertId := this.GetString("SupplierCertId")
  864. var errinfo ErrorInfo
  865. if Id == "" {
  866. errinfo.Message = "操作失败!请求信息不完整"
  867. errinfo.Code = -2
  868. this.Data["json"] = &errinfo
  869. this.ServeJSON()
  870. return
  871. }
  872. //根据Id查出OilSupplierCertSub的SubClassId
  873. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) //获得数据库引擎
  874. where := "delete from " + OilSupplierCertSubName + " where Id in (" + Id + ")" // 没有删除的准入范围
  875. svc.DBE.Exec(where)
  876. // TODO: 删除准入范围和资质对应关系表
  877. /*whereCert2File := "delete from " + OilSupplierCert2FileName + " where SupplierCertSubId in (" + Id + ")" // 没有删除的准入范围
  878. svc.DBE.Exec(whereCert2File)*/
  879. errinfo.Message = "删除成功!"
  880. errinfo.Code = 0
  881. this.Data["json"] = &errinfo
  882. this.ServeJSON()
  883. }
  884. // @Title 获取待审核业务列表
  885. // @Description get user by token
  886. // @Success 200 {object} models.Userblood
  887. // @router /auditbuslist [get]
  888. func (this *OilSupplierCertSubController) AuditbusList() {
  889. var list []suppliercertsub.OilSupplierCertSub
  890. //获取分页信息
  891. page := this.GetPageInfoForm()
  892. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  893. orderby := "CreateOn desc"
  894. Order := this.GetString("Order")
  895. Prop := this.GetString("Prop")
  896. if Order != "" && Prop != "" {
  897. orderby = Prop + " " + Order
  898. }
  899. where := "1 = 1"
  900. SupplierCertId := this.GetString("SupplierCertId")
  901. if SupplierCertId != "" {
  902. where = where + " and a.SupplierCertId = '" + SupplierCertId + "'"
  903. }
  904. total, list := svc.GetWaitAuditBusinesslist(page.CurrentPage, page.Size, orderby, OilSupplierCertSubName, OilClassOrgSettingName, where)
  905. var datainfo DataInfo
  906. datainfo.Items = list
  907. datainfo.CurrentItemCount = total
  908. this.Data["json"] = &datainfo
  909. this.ServeJSON()
  910. }
  911. // @Title 获取审核意见列表
  912. // @Description 获取审核意见列表
  913. // @Success 200 {object} controllers.Request
  914. // @router /opinionlist [get]
  915. func (this *OilSupplierCertSubController) OpinionList() {
  916. SupplierCertSubId := this.GetString("SupplierCertSubId")
  917. var list []suppliercertsub.OilSupplierOpinion
  918. where := " 1 = 1 "
  919. if SupplierCertSubId != "" {
  920. where = where + " and SupplierCertSubId = '" + SupplierCertSubId + "'"
  921. }
  922. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  923. svc.GetEntitysByWhere(OilSupplierOpinionName, where, &list)
  924. var datainfo DataInfo
  925. datainfo.Items = list
  926. this.Data["json"] = &datainfo
  927. this.ServeJSON()
  928. }
  929. // @Title 新增审核意见
  930. // @Description 新增审核意见
  931. // @Success 200 {object} controllers.Request
  932. // @router /addopinion [post]
  933. func (this *OilSupplierCertSubController) AddOpinion() {
  934. var model suppliercertsub.OilSupplierOpinion
  935. var jsonblob = this.Ctx.Input.RequestBody
  936. json.Unmarshal(jsonblob, &model)
  937. model.AuditorName = this.User.Realname
  938. model.AuditorId, _ = utils.StrTo(this.User.Id).Int()
  939. model.CreateBy = this.User.Realname
  940. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  941. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  942. //where := "SupplierCertSubId=" + strconv.Itoa(model.SupplierCertSubId) + " and AuditorId= " + strconv.Itoa(model.AuditorId) + " and Status = '" + model.Status + "'"
  943. //svc.DeleteEntityBytbl(OilSupplierOpinionName, where)
  944. _, err := svc.InsertEntityBytbl(OilSupplierOpinionName, &model)
  945. var errinfo ErrorDataInfo
  946. if err == nil {
  947. errinfo.Message = "操作成功!"
  948. errinfo.Code = 0
  949. errinfo.Item = model.Id
  950. this.Data["json"] = &errinfo
  951. this.ServeJSON()
  952. } else {
  953. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  954. errinfo.Code = -1
  955. this.Data["json"] = &errinfo
  956. this.ServeJSON()
  957. }
  958. }
  959. // @Title 更新准入项状态
  960. // @Description
  961. // @router /updatestatus/:Id/:Status [get]
  962. func (this *OilSupplierCertSubController) UpdateStatus() {
  963. Id := this.Ctx.Input.Param(":Id")
  964. Status := this.Ctx.Input.Param(":Status")
  965. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  966. var error error
  967. if Status == "1" {
  968. _, error = svc.DBE.Exec("update " + OilSupplierCertSubName + " set CertSubStatus='2' where Id=" + Id + "")
  969. } else {
  970. _, error = svc.DBE.Exec("update " + OilSupplierCertSubName + " set CertSubStatus='1' where Id=" + Id + "")
  971. }
  972. var errinfo ErrorDataInfo
  973. if error == nil {
  974. errinfo.Message = "操作成功!"
  975. errinfo.Code = 0
  976. this.Data["json"] = &errinfo
  977. this.ServeJSON()
  978. } else {
  979. errinfo.Message = "操作失败!"
  980. errinfo.Code = -1
  981. this.Data["json"] = &errinfo
  982. this.ServeJSON()
  983. }
  984. }
  985. // @Title 修改是否为供应商
  986. // @Description
  987. // @router /modify-manufacturer/:id [post]
  988. func (this *OilSupplierCertSubController) SetManufacturer() {
  989. // certSubId, error := strconv.Atoi(this.Ctx.Input.Param(":id"))
  990. certSubId := this.Ctx.Input.Param(":id")
  991. var manufacturerChangeDTO suppliercertsub.ManufacturerChangeDTO
  992. var jsonblob = this.Ctx.Input.RequestBody
  993. json.Unmarshal(jsonblob, &manufacturerChangeDTO)
  994. /**
  995. manufacturerChangeDTO.CertSubIdList = [] int{certSubId}
  996. invalidCertMsg := setManufacturerHandler(manufacturerChangeDTO)
  997. */
  998. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  999. strIsManufacturer := strconv.Itoa(manufacturerChangeDTO.IsManufacturer)
  1000. sqlStr := "update OilSupplierCertSub set IsManufacturer='" + strIsManufacturer + "' where Id='" + certSubId + "'"
  1001. svc.DBE.Exec(sqlStr)
  1002. var errinfo ErrorDataInfo
  1003. errinfo.Message = "修改成功!"
  1004. errinfo.Code = 0
  1005. this.Data["json"] = &errinfo
  1006. this.ServeJSON()
  1007. /*var errinfo ErrorDataInfo
  1008. if error == nil && invalidCertMsg == "" {
  1009. errinfo.Message = "修改成功!"
  1010. errinfo.Code = 0
  1011. this.Data["json"] = &errinfo
  1012. this.ServeJSON()
  1013. } else {
  1014. errinfo.Message = "修改失败!" + invalidCertMsg
  1015. errinfo.Code = -1
  1016. this.Data["json"] = &errinfo
  1017. this.ServeJSON()
  1018. }*/
  1019. }
  1020. // @Title 批量修改是否为供应商
  1021. // @Description
  1022. // @router /modify-manufacturers/:certid [post]
  1023. func (this *OilSupplierCertSubController) UpdateManufacturers() {
  1024. certId := this.Ctx.Input.Param(":certid")
  1025. var manufacturerChangeDTO suppliercertsub.ManufacturerChangeDTO
  1026. var jsonblob = this.Ctx.Input.RequestBody
  1027. json.Unmarshal(jsonblob, &manufacturerChangeDTO)
  1028. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  1029. strIsManufacturer := strconv.Itoa(manufacturerChangeDTO.IsManufacturer)
  1030. sqlStr := "update OilSupplierCertSub set IsManufacturer='" + strIsManufacturer + "' where SupplierCertId='" + certId + "'"
  1031. svc.DBE.Exec(sqlStr)
  1032. var errinfo ErrorDataInfo
  1033. errinfo.Message = "修改成功!"
  1034. errinfo.Code = 0
  1035. this.Data["json"] = &errinfo
  1036. this.ServeJSON()
  1037. }
  1038. func setManufacturerHandler(manufacturerChangeDTO suppliercertsub.ManufacturerChangeDTO) (invalidCertMsg string) {
  1039. CertSubIdList := manufacturerChangeDTO.CertSubIdList
  1040. IsManufacturer := manufacturerChangeDTO.IsManufacturer
  1041. SupplierId := manufacturerChangeDTO.SupplierId
  1042. SupplierCertId := manufacturerChangeDTO.SupplierCertId
  1043. //物资类
  1044. SupplierTypeCode := "01"
  1045. // 供应商主表
  1046. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  1047. var supplierEntity supplier.OilSupplier
  1048. svcSupplier.GetEntityById(SupplierId, &supplierEntity)
  1049. // 供应商准入申请表
  1050. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  1051. var certEntity suppliercert.OilSupplierCert
  1052. svcCert.GetEntityById(SupplierCertId, &certEntity)
  1053. //------ 查询出企业已有哪些资质 Start------------
  1054. var tableheaderList []supplierfile.OilSupplierFile
  1055. fileSql := "SELECT * from OilSupplierFile WHERE SupplierId='" + strconv.Itoa(SupplierId) + "'"
  1056. fileSql += " AND (SupplierTypeCode='" + SupplierTypeCode + "' or SupplierTypeCode='000')"
  1057. svcHeader := supplierfile.GetSupplierfileService(utils.DBE)
  1058. svcHeader.DBE.SQL(fileSql).Find(&tableheaderList)
  1059. var companyHasHeaders string
  1060. for _, tableheader := range tableheaderList {
  1061. companyHasHeaders += tableheader.NeedFileType + ","
  1062. }
  1063. //------ 查询出企业已有哪些资质 End--------------
  1064. for _, certSubId := range CertSubIdList {
  1065. // 当前修改的记录
  1066. var certSubEntity suppliercertsub.OilSupplierCertSub
  1067. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  1068. svc.DBE.Where("Id=" + strconv.Itoa(certSubId)).Get(&certSubEntity)
  1069. //--------------取出准入项需要的资质 Start--------------------------
  1070. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  1071. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  1072. needList := filesvc.GetGoodsNeedFileList(strconv.Itoa(certSubId), strconv.Itoa(IsManufacturer)) // 需要的资质
  1073. //三证合一或五证合一不需要的字段
  1074. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  1075. if certEntity.InStyle == "4" {
  1076. var needFile supplierfile.FileList
  1077. //战略合作协议扫描件
  1078. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  1079. needList = append(needList, needFile)
  1080. }
  1081. if certSubEntity.IsManufacturer == 1 { //制造商
  1082. var needFile supplierfile.FileList
  1083. // 中油集团公司产品质量认可证书
  1084. CNPCrenkezhengshu := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CNPCrenkezhengshu")
  1085. needFile.FileName = CNPCrenkezhengshu
  1086. needList = append(needList, needFile)
  1087. }
  1088. //--------------取出准入项需要的资质 End--------------------------
  1089. //--------------检查是否符合资质 Start--------------------------
  1090. certsValid := true
  1091. for _, needHeader := range needList {
  1092. if (supplierEntity.CredentialFlag == "1" || supplierEntity.CredentialFlag == "2") &&
  1093. strings.Contains(mergerCertSkipField, needHeader.FileName+",") {
  1094. //三证合一或五证合一的证件,不需要验证了
  1095. continue
  1096. }
  1097. if !strings.Contains(companyHasHeaders, needHeader.FileName+",") {
  1098. //缺少资质,不会保存
  1099. invalidCertMsg += certSubEntity.Code + " " + certSubEntity.Name + "(缺少:" + needHeader.FileName + ") ,"
  1100. certsValid = false
  1101. break
  1102. }
  1103. }
  1104. if !certsValid {
  1105. //缺少资质,不能修改
  1106. continue
  1107. }
  1108. //--------------检查是否符合资质 End--------------------------
  1109. //修改状态
  1110. certSubEntity.IsManufacturer = IsManufacturer
  1111. svc.DBE.Where("Id=" + strconv.Itoa(certSubId)).Update(&certSubEntity)
  1112. }
  1113. return invalidCertMsg
  1114. }
  1115. // TODO: 删除准入范围和资质对应关系表
  1116. /* type OilSupplierCert2File struct {
  1117. Id int `json:"not null pk autoincr INT(10)"`
  1118. certSubId int `json:"not null default 0 comment('供方基本信息表主键') INT(10)"`
  1119. certSubStatus int `json:"not null default 0 comment('供方准入证书信息表主键') INT(10)"`
  1120. stopReason string `json:"not null default '0' comment('准入类别代码(1 物资类,2 基建类,3 技术服务类)') VARCHAR(5)"`
  1121. }*/
  1122. type LostCertFiles struct {
  1123. Code string
  1124. Name string
  1125. CertFileName string
  1126. }
  1127. // @Title 记录准入项状态更改日志
  1128. // @Description
  1129. // @router /updatestatuswithlog/:Id [post]
  1130. func (this *OilSupplierCertSubController) UpdateStatusWithLog() {
  1131. Id := this.Ctx.Input.Param(":Id")
  1132. reasonSvc := supplierpausereason.GetOilSupplierPauseReasonService(utils.DBE)
  1133. var pauseModel supplierpausereason.OilSupplierPauseReason
  1134. var jsonblob = this.Ctx.Input.RequestBody
  1135. json.Unmarshal(jsonblob, &pauseModel)
  1136. Status := pauseModel.CertSubStatus
  1137. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  1138. var error error
  1139. if Status == "1" {
  1140. _, error = svc.DBE.Exec("update " + OilSupplierCertSubName + " set CertSubStatus='2' where Id=" + Id + "")
  1141. pauseModel.CertSubStatus = "2"
  1142. } else {
  1143. _, error = svc.DBE.Exec("update " + OilSupplierCertSubName + " set CertSubStatus='1' where Id=" + Id + "")
  1144. pauseModel.CertSubStatus = "1"
  1145. }
  1146. pauseModel.CreateOn = time.Now()
  1147. pauseModel.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1148. pauseModel.CreateBy = this.User.Realname
  1149. reasonSvc.InsertEntity(pauseModel)
  1150. var errinfo ErrorDataInfo
  1151. if error == nil {
  1152. errinfo.Message = "操作成功!"
  1153. errinfo.Code = 0
  1154. this.Data["json"] = &errinfo
  1155. this.ServeJSON()
  1156. } else {
  1157. errinfo.Message = "操作失败!"
  1158. errinfo.Code = -1
  1159. this.Data["json"] = &errinfo
  1160. this.ServeJSON()
  1161. }
  1162. }
  1163. type FileList struct {
  1164. FileName string
  1165. }
  1166. // @Title 物资类准入提交审核检查资质 2021-01-08
  1167. // @Description 物资类准入提交审核检查资质
  1168. // @Success 200 {object} business.device.DeviceChannels
  1169. // @router /checkSubFile [post]
  1170. func (this *OilSupplierCertSubController) CheckSubFile () {
  1171. var jsonblob = this.Ctx.Input.RequestBody
  1172. var datamain suppliercertsub.OilSupplierCertSub
  1173. var dataother []suppliercertsub.OilSupplierCertSub
  1174. json.Unmarshal(jsonblob, &datamain)
  1175. var supplierCertModel suppliercert.OilSupplierCert
  1176. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  1177. svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel)
  1178. var lostCertList []LostCertFiles
  1179. // 查询出已有哪些资质
  1180. supplierId := datamain.SupplierId
  1181. supplierTypeCode := datamain.SupplierTypeCode
  1182. var tableheaderList []supplierfile.OilSupplierFile
  1183. fileSql := "SELECT * from OilSupplierFile WHERE SupplierId='" + strconv.Itoa(supplierId) + "'"
  1184. fileSql += " AND (SupplierTypeCode='" + supplierTypeCode + "' or SupplierTypeCode='000')"
  1185. svcHeader := tableheader.GetTableHeaderService(utils.DBE)
  1186. svcHeader.DBE.SQL(fileSql).Find(&tableheaderList)
  1187. var companyHasHeaders string
  1188. for _, tableheader := range tableheaderList {
  1189. companyHasHeaders += tableheader.NeedFileType + ","
  1190. }
  1191. var supplierModel supplier.OilSupplier
  1192. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  1193. svcSupplier.GetEntityById(supplierId, &supplierModel)
  1194. where := "SupplierId = " + strconv.Itoa(supplierId) + " and SupplierCertId = "+ strconv.Itoa(datamain.SupplierCertId) + " and SupplierTypeCode = "+ supplierTypeCode
  1195. svcSupplier.GetEntitysByWhere(OilSupplierCertSubName, where, &dataother)
  1196. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  1197. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  1198. var needList []supplierfile.FileList
  1199. //逐条检查需要的资质
  1200. for _,sub := range dataother {
  1201. if supplierTypeCode == "01" {
  1202. if supplierModel.OperType == "制造商" {
  1203. datamain.IsManufacturer = 1
  1204. } else if supplierModel.OperType == "贸易商" || supplierModel.OperType == "代理商"{
  1205. datamain.IsManufacturer = 2
  1206. if sub.IsManufacturer == 1 {
  1207. var tmpLostCert LostCertFiles
  1208. tmpLostCert.Code = "0"
  1209. tmpLostCert.Name = ""
  1210. tmpLostCert.CertFileName = "非制造商准入范围不能为制造商,请手动修改"
  1211. lostCertList = append(lostCertList, tmpLostCert)
  1212. break
  1213. }
  1214. }
  1215. //需要的资质
  1216. needList = filesvc.GetGoodsNeedFileList(strconv.Itoa(sub.SubClassId), strconv.Itoa(datamain.IsManufacturer))
  1217. } else if supplierTypeCode == "02" {
  1218. needList = filesvc.GetBasicNeedFileList(strconv.Itoa(sub.SubClassId))
  1219. } else if supplierTypeCode == "03" {
  1220. needList = filesvc.GetTechNeedFileList(strconv.Itoa(sub.SubClassId))
  1221. }
  1222. //三证合一或五证合一不需要的字段
  1223. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  1224. if supplierCertModel.InStyle == "4" {
  1225. var needFile supplierfile.FileList
  1226. //战略合作协议扫描件
  1227. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  1228. needList = append(needList, needFile)
  1229. }
  1230. if supplierCertModel.InStyle == "6" {
  1231. var needFile supplierfile.FileList
  1232. //招标中标结果
  1233. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "TheTender")
  1234. needList = append(needList, needFile)
  1235. }
  1236. if datamain.IsManufacturer == 1 { //制造商
  1237. var needFile supplierfile.FileList
  1238. // 质量管理体系认证证书
  1239. CNPCrenkezhengshu := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CNPCrenkezhengshu")
  1240. needFile.FileName = CNPCrenkezhengshu
  1241. needList = append(needList, needFile)
  1242. }
  1243. for _, needHeader := range needList {
  1244. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") &&
  1245. strings.Contains(mergerCertSkipField, needHeader.FileName+",") {
  1246. //三证合一或五证合一的证件,不需要验证了
  1247. continue
  1248. }
  1249. var fileist1 supplierfile.OilSupplierFile
  1250. where1 := " SupplierId = '" + strconv.Itoa(supplierId) + "' and NeedFileType = '" + needHeader.FileName + "'"
  1251. filesvc.GetEntityByWhere(OilSupplierFileName, where1, &fileist1)
  1252. var filelist2 suppliercertappendsub.OilAppendChangeDetail
  1253. where2 := " SupplierId = '" + strconv.Itoa(supplierId) + "' and NeedFileType = '" +needHeader.FileName + "'"
  1254. svc2 := suppliercertappendsub.GetOilSupplierCertAppendSubService (utils.DBE)
  1255. svc2.GetEntityByWhere(OilAppendChangeDetailName, where2, &filelist2)
  1256. if !strings.Contains(companyHasHeaders, needHeader.FileName+",") {
  1257. var tmpLostCert LostCertFiles
  1258. tmpLostCert.Code = sub.Code
  1259. tmpLostCert.Name = sub.Name
  1260. tmpLostCert.CertFileName = needHeader.FileName
  1261. lostCertList = append(lostCertList, tmpLostCert)
  1262. } else {
  1263. if filelist2.FileName == "" && fileist1.FileName == "" {
  1264. //缺少的资质
  1265. var tmpLostCert LostCertFiles
  1266. tmpLostCert.Code = sub.Code
  1267. tmpLostCert.Name = sub.Name
  1268. tmpLostCert.CertFileName = needHeader.FileName
  1269. lostCertList = append(lostCertList, tmpLostCert)
  1270. }
  1271. }
  1272. }
  1273. }
  1274. var errinfo ErrorDataInfo
  1275. if len(lostCertList) <= 0 {
  1276. errinfo.Code = 0
  1277. errinfo.Message = "验证通过!"
  1278. this.Data["json"] = nil
  1279. } else {
  1280. errinfo.Code = -1
  1281. errinfo.Message = "缺少资质!"
  1282. this.Data["json"] = &lostCertList
  1283. }
  1284. this.ServeJSON()
  1285. }