suppliercertsub.go 44 KB

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