suppliercertsub.go 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  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 []supplierfile.OilSupplierFile
  311. fileSql := "SELECT * from OilSupplierFile WHERE SupplierId='" + strconv.Itoa(supplierId) + "'"
  312. fileSql += " AND (SupplierTypeCode='" + supplierTypeCode + "' or SupplierTypeCode='000')"
  313. svcHeader := tableheader.GetTableHeaderService(utils.DBE)
  314. svcHeader.DBE.SQL(fileSql).Find(&tableheaderList)
  315. var companyHasHeaders string
  316. for _, tableheader := range tableheaderList {
  317. companyHasHeaders += tableheader.NeedFileType + ","
  318. }
  319. var supplierModel supplier.OilSupplier
  320. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  321. svcSupplier.GetEntityById(datamain.SupplierId, &supplierModel)
  322. //逐条检查需要的资质
  323. for n := 0; n < len(dataother.CheckList); n++ {
  324. if supplierModel.OperType == "制造商" {
  325. datamain.IsManufacturer = 1
  326. } else {
  327. datamain.IsManufacturer = 2
  328. }
  329. //检查是否资质全面
  330. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  331. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  332. needList := filesvc.GetGoodsNeedFileList(dataother.CheckList[n].Id, strconv.Itoa(datamain.IsManufacturer)) // 需要的资质
  333. //三证合一或五证合一不需要的字段
  334. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  335. if supplierCertModel.InStyle == "4" {
  336. var needFile supplierfile.FileList
  337. //战略合作协议扫描件
  338. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  339. needList = append(needList, needFile)
  340. }
  341. if datamain.IsManufacturer == 1 { //制造商
  342. var needFile supplierfile.FileList
  343. // 中油集团公司产品质量认可证书
  344. CNPCrenkezhengshu := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CNPCrenkezhengshu")
  345. needFile.FileName = CNPCrenkezhengshu
  346. needList = append(needList, needFile)
  347. }
  348. for _, needHeader := range needList {
  349. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") &&
  350. strings.Contains(mergerCertSkipField, needHeader.FileName+",") {
  351. //三证合一或五证合一的证件,不需要验证了
  352. continue
  353. }
  354. if !strings.Contains(companyHasHeaders, needHeader.FileName+",") {
  355. //缺少的资质
  356. var tmpLostCert LostCertFiles
  357. tmpLostCert.Code = dataother.CheckList[n].Code
  358. tmpLostCert.Name = dataother.CheckList[n].Name
  359. tmpLostCert.CertFileName = needHeader.FileName
  360. lostCertList = append(lostCertList, tmpLostCert)
  361. }
  362. }
  363. }
  364. var errinfo ErrorDataInfo
  365. if len(lostCertList) <= 0 {
  366. errinfo.Code = 0
  367. errinfo.Message = "验证通过!"
  368. this.Data["json"] = nil
  369. } else {
  370. errinfo.Code = -1
  371. errinfo.Message = "缺少资质!"
  372. this.Data["json"] = &lostCertList
  373. }
  374. this.ServeJSON()
  375. }
  376. // @Title 批量添加准入范围--物资类
  377. // @Description 批量添加准入范围
  378. // @Success 200 {object} business.device.DeviceChannels
  379. // @router /add-goods-certsub-filter [post]
  380. func (this *OilSupplierCertSubController) AddGoodsByFilter() {
  381. var jsonblob = this.Ctx.Input.RequestBody
  382. var datamain suppliercertsub.OilSupplierCertSub
  383. var dataother suppliercertsub.SupplierCertSubModel
  384. json.Unmarshal(jsonblob, &datamain)
  385. json.Unmarshal(jsonblob, &dataother)
  386. var supplierCertModel suppliercert.OilSupplierCert
  387. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  388. svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel)
  389. // 查询出已有哪些资质
  390. supplierId := dataother.SupplierId
  391. supplierTypeCode := dataother.SupplierTypeCode
  392. var tableheaderList []tableheader.BaseTableheader
  393. fileSql := "SELECT b.* from OilSupplierFile a LEFT JOIN Base_TableHeader b on a.NeedFileType=b.Name AND "
  394. fileSql += " a.SupplierTypeCode=b.CategoryCode WHERE a.SupplierId='" + strconv.Itoa(supplierId) + "'"
  395. fileSql += " AND (a.SupplierTypeCode='" + supplierTypeCode + "' or a.SupplierTypeCode='000')"
  396. svcHeader := tableheader.GetTableHeaderService(utils.DBE)
  397. svcHeader.DBE.SQL(fileSql).Find(&tableheaderList)
  398. var companyHasHeaders string
  399. for _, tableheader := range tableheaderList {
  400. companyHasHeaders += tableheader.Name + ","
  401. }
  402. var supplierModel supplier.OilSupplier
  403. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  404. svcSupplier.GetEntityById(datamain.SupplierId, &supplierModel)
  405. // 记录缺少的证件
  406. invalidCertMsg := ""
  407. // 记录保存条数
  408. vaildCnt := 0
  409. //逐条检查需要的资质,符合才会保存
  410. for n := 0; n < len(dataother.CheckList); n++ {
  411. where_sub := "SupplierTypeCode = 01 and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  412. where_sub += " and SupplierCertId = '" + strconv.Itoa(dataother.SupplierCertId) + "'"
  413. where_sub += " and SubClassId = '" + dataother.CheckList[n].Id + "'"
  414. var model suppliercertsub.OilSupplierCertSub
  415. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  416. has := svc.GetEntityByWhere(OilSupplierCertSubName, where_sub, &model)
  417. if !has {
  418. if supplierModel.OperType == "制造商" {
  419. datamain.IsManufacturer = 1
  420. } else {
  421. datamain.IsManufacturer = 2
  422. }
  423. //检查是否资质全面
  424. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  425. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  426. needList := filesvc.GetGoodsNeedFileList(dataother.CheckList[n].Id, strconv.Itoa(datamain.IsManufacturer)) // 需要的资质
  427. //三证合一或五证合一不需要的字段
  428. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  429. if supplierCertModel.InStyle == "4" {
  430. var needFile supplierfile.FileList
  431. //战略合作协议扫描件
  432. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  433. needList = append(needList, needFile)
  434. }
  435. if datamain.IsManufacturer == 1 { //制造商
  436. var needFile supplierfile.FileList
  437. // 中油集团公司产品质量认可证书
  438. CNPCrenkezhengshu := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CNPCrenkezhengshu")
  439. needFile.FileName = CNPCrenkezhengshu
  440. needList = append(needList, needFile)
  441. }
  442. certsValid := true
  443. for _, needHeader := range needList {
  444. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") &&
  445. strings.Contains(mergerCertSkipField, needHeader.FileName+",") {
  446. //三证合一或五证合一的证件,不需要验证了
  447. continue
  448. }
  449. if !strings.Contains(companyHasHeaders, needHeader.FileName+",") {
  450. //缺少资质,不会保存
  451. invalidCertMsg += dataother.CheckList[n].Code + " " + dataother.CheckList[n].Name + "(缺少:" + needHeader.FileName + ") ,"
  452. certsValid = false
  453. break
  454. }
  455. }
  456. if !certsValid {
  457. //缺少资质,不会保存
  458. continue
  459. }
  460. datamain.SubClassId, _ = utils.StrTo(dataother.CheckList[n].Id).Int()
  461. datamain.Code = dataother.CheckList[n].Code
  462. datamain.Name = dataother.CheckList[n].Name
  463. datamain.GoodsLevel = dataother.CheckList[n].GoodsLevel
  464. datamain.Remark = dataother.Remark
  465. datamain.IsDelete = 0
  466. datamain.CreateBy = this.User.Realname
  467. datamain.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  468. unitsvc := organize.GetOrganizeService(utils.DBE)
  469. unitid := unitsvc.GetMyUnitDepartmentId(this.User.DepartmentId)
  470. if unitid == "100000095" { // 100000095 企管法规处(内控与风险管理处)
  471. datamain.CertSubStatus = "1"
  472. }
  473. //插入准入范围表
  474. svc.InsertEntityBytbl(OilSupplierCertSubName, &datamain)
  475. //插入准入范围所需资质记录表
  476. for _, needHeader := range needList {
  477. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") &&
  478. strings.Contains(mergerCertSkipField, needHeader.FileName+",") {
  479. //三证合一或五证合一的证件,不需要保存
  480. continue
  481. }
  482. //加入对应表OilSupplierCert2File, 保存准入项所需的资质关系
  483. var cert2File suppliercertsub.OilSupplierCert2File //创建结构体
  484. cert2File.SupplierId = dataother.SupplierId
  485. cert2File.SupplierCertId = dataother.SupplierCertId
  486. cert2File.SupplierCertSubId = datamain.Id
  487. cert2File.SupplierTypeCode = dataother.SupplierTypeCode
  488. cert2File.IsManuf = strconv.Itoa(datamain.IsManufacturer)
  489. cert2File.SubClassId, _ = utils.StrTo(dataother.CheckList[n].Id).Int()
  490. cert2File.Code = dataother.CheckList[n].Code
  491. cert2File.Name = dataother.CheckList[n].Name
  492. cert2File.NeedFileType = needHeader.FileName
  493. svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File)
  494. }
  495. vaildCnt++
  496. }
  497. }
  498. var errinfo ErrorDataInfo
  499. if invalidCertMsg == "" {
  500. errinfo.Code = 0
  501. errinfo.Message = "操作成功!"
  502. } else if vaildCnt > 0 {
  503. errinfo.Code = -1
  504. errinfo.Message = "部分成功!" + invalidCertMsg
  505. } else {
  506. errinfo.Message = invalidCertMsg
  507. }
  508. this.Data["json"] = &errinfo
  509. this.ServeJSON()
  510. }
  511. // @Title 批量添加准入范围--技术服务类
  512. // @Description 批量添加准入范围
  513. // @Success 200 {object} business.device.DeviceChannels
  514. // @router /tech-cert-lost [post]
  515. func (this *OilSupplierCertSubController) CheckTechCertLost() {
  516. var jsonblob = this.Ctx.Input.RequestBody
  517. var datamain suppliercertsub.OilSupplierCertSub
  518. var dataother suppliercertsub.TechnologySubModel
  519. json.Unmarshal(jsonblob, &datamain)
  520. json.Unmarshal(jsonblob, &dataother)
  521. var supplierCertModel suppliercert.OilSupplierCert
  522. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  523. svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel)
  524. var supplierModel supplier.OilSupplier
  525. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  526. svcSupplier.GetEntityById(datamain.SupplierId, &supplierModel)
  527. var lostCertList []LostCertFiles
  528. for n := 0; n < len(dataother.CheckList); n++ {
  529. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  530. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  531. needList := filesvc.GetTechNeedFileList(strconv.Itoa(dataother.CheckList[n].Id))
  532. if supplierCertModel.InStyle == "4" {
  533. var needFile supplierfile.FileList
  534. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  535. needList = append(needList, needFile)
  536. }
  537. var fileist []supplierfile.OilSupplierFile
  538. where := "SupplierTypeCode in (03,000) and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  539. svcSupplier.GetEntitysByWhere(OilSupplierFileName, where, &fileist)
  540. var companyHasHeaders string
  541. for _, tableheader := range fileist {
  542. companyHasHeaders += tableheader.NeedFileType + ","
  543. }
  544. //三证合一或五证合一不需要的字段
  545. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  546. for i := 0; i < len(needList); i++ {
  547. var entity supplierfile.OilSupplierFile
  548. entity.SupplierId = dataother.SupplierId
  549. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了
  550. continue
  551. }
  552. if !strings.Contains(companyHasHeaders, needList[i].FileName+",") {
  553. //缺少的资质
  554. var tmpLostCert LostCertFiles
  555. tmpLostCert.Code = dataother.CheckList[n].Code
  556. tmpLostCert.Name = dataother.CheckList[n].Name
  557. tmpLostCert.CertFileName = needList[i].FileName
  558. lostCertList = append(lostCertList, tmpLostCert)
  559. }
  560. }
  561. }
  562. var errinfo ErrorDataInfo
  563. if len(lostCertList) <= 0 {
  564. errinfo.Code = 0
  565. errinfo.Message = "验证通过!"
  566. this.Data["json"] = nil
  567. } else {
  568. errinfo.Code = -1
  569. errinfo.Message = "缺少资质!"
  570. this.Data["json"] = &lostCertList
  571. }
  572. this.ServeJSON()
  573. }
  574. // @Title 批量添加准入范围--技术服务类
  575. // @Description 批量添加准入范围
  576. // @Success 200 {object} business.device.DeviceChannels
  577. // @router /addtechbus [post]
  578. func (this *OilSupplierCertSubController) AddTechBus() {
  579. //TODO: 没有像AddGoodsByFilter一样,保存时做合法性验证,因为在保存之前已经在前台调用了CheckTechCertLost验证过了,
  580. // 以后有时间再加上
  581. var jsonblob = this.Ctx.Input.RequestBody
  582. var datamain suppliercertsub.OilSupplierCertSub
  583. var dataother suppliercertsub.TechnologySubModel
  584. json.Unmarshal(jsonblob, &datamain)
  585. json.Unmarshal(jsonblob, &dataother)
  586. var supplierCertModel suppliercert.OilSupplierCert
  587. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  588. svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel)
  589. var supplierModel supplier.OilSupplier
  590. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  591. svcSupplier.GetEntityById(datamain.SupplierId, &supplierModel)
  592. for n := 0; n < len(dataother.CheckList); n++ {
  593. where_sub := "SupplierTypeCode = 03 and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  594. where_sub += " and SupplierCertId = '" + strconv.Itoa(dataother.SupplierCertId) + "'"
  595. where_sub += " and SubClassId = '" + strconv.Itoa(dataother.CheckList[n].Id) + "'"
  596. var model suppliercertsub.OilSupplierCertSub
  597. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  598. has := svc.GetEntityByWhere(OilSupplierCertSubName, where_sub, &model)
  599. if !has {
  600. datamain.SubClassId = dataother.CheckList[n].Id
  601. datamain.Code = dataother.CheckList[n].Code
  602. datamain.Name = dataother.CheckList[n].Name
  603. datamain.Remark = dataother.Remark
  604. datamain.IsDelete = 0
  605. datamain.CreateBy = this.User.Realname
  606. datamain.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  607. unitsvc := organize.GetOrganizeService(utils.DBE)
  608. unitid := unitsvc.GetMyUnitDepartmentId(this.User.DepartmentId)
  609. if unitid == "100000095" {
  610. datamain.CertSubStatus = "1"
  611. }
  612. svc.InsertEntityBytbl(OilSupplierCertSubName, &datamain)
  613. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  614. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  615. needList := filesvc.GetTechNeedFileList(strconv.Itoa(dataother.CheckList[n].Id))
  616. if supplierCertModel.InStyle == "4" {
  617. var needFile supplierfile.FileList
  618. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  619. needList = append(needList, needFile)
  620. }
  621. var list []supplierfile.OilSupplierFile
  622. where := "SupplierTypeCode in (03,000) and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
  623. svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
  624. //三证合一或五证合一不需要的字段
  625. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  626. // "营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件,"
  627. // mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName")
  628. for i := 0; i < len(needList); i++ {
  629. var entity supplierfile.OilSupplierFile
  630. entity.SupplierId = dataother.SupplierId
  631. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了
  632. continue
  633. }
  634. //加入对应表OilSupplierCert2File
  635. var cert2File suppliercertsub.OilSupplierCert2File //创建结构体
  636. cert2File.SupplierId = dataother.SupplierId
  637. cert2File.SupplierCertId = dataother.SupplierCertId
  638. cert2File.SupplierCertSubId = datamain.Id
  639. cert2File.SupplierTypeCode = dataother.SupplierTypeCode
  640. cert2File.SubClassId = dataother.CheckList[n].Id
  641. cert2File.Code = dataother.CheckList[n].Code
  642. cert2File.Name = dataother.CheckList[n].Name
  643. cert2File.NeedFileType = needList[i].FileName
  644. svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File)
  645. }
  646. }
  647. }
  648. var errinfo ErrorDataInfo
  649. errinfo.Message = "操作成功!"
  650. errinfo.Code = 0
  651. this.Data["json"] = &errinfo
  652. this.ServeJSON()
  653. }
  654. // @Title 检查资质是否完整--基建类
  655. // @Description 批量添加准入范围
  656. // @Success 200 {object} lostCertList []LostCertFiles
  657. // @router /check-basis-lost [post]
  658. func (this *OilSupplierCertSubController) CheckBasisBusinessLost() {
  659. var model suppliercertsub.OilSupplierCertSub
  660. var err error
  661. var jsonblob = this.Ctx.Input.RequestBody
  662. json.Unmarshal(jsonblob, &model)
  663. var supplierCertModel suppliercert.OilSupplierCert
  664. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  665. svcCert.GetEntityById(model.SupplierCertId, &supplierCertModel)
  666. var supplierModel supplier.OilSupplier
  667. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  668. svcSupplier.GetEntityById(model.SupplierId, &supplierModel)
  669. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  670. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  671. var needList []supplierfile.FileList
  672. var lostCertList []LostCertFiles
  673. needList = filesvc.GetBasicNeedFileList(strconv.Itoa(model.SubClassId))
  674. if supplierCertModel.InStyle == "4" {
  675. var needFile supplierfile.FileList
  676. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  677. needList = append(needList, needFile)
  678. }
  679. if err == nil {
  680. var list []supplierfile.OilSupplierFile
  681. where := "SupplierTypeCode in (02,000) and SupplierId = '" + strconv.Itoa(model.SupplierId) + "'"
  682. svcCert.GetEntitysByWhere(OilSupplierFileName, where, &list)
  683. var companyHasHeaders string
  684. for _, tableheader := range list {
  685. companyHasHeaders += tableheader.NeedFileType + ","
  686. }
  687. //三证合一或五证合一不需要的字段
  688. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  689. //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件,"
  690. // mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName")
  691. for i := 0; i < len(needList); i++ {
  692. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了
  693. continue
  694. }
  695. if !strings.Contains(companyHasHeaders, needList[i].FileName+",") {
  696. //缺少的资质
  697. var tmpLostCert LostCertFiles
  698. tmpLostCert.Code = model.Code
  699. tmpLostCert.Name = model.Name
  700. tmpLostCert.CertFileName = needList[i].FileName
  701. lostCertList = append(lostCertList, tmpLostCert)
  702. }
  703. }
  704. }
  705. var errinfo ErrorDataInfo
  706. if len(lostCertList) <= 0 {
  707. errinfo.Code = 0
  708. errinfo.Message = "验证通过!"
  709. this.Data["json"] = nil
  710. } else {
  711. errinfo.Code = -1
  712. errinfo.Message = "缺少资质!"
  713. this.Data["json"] = &lostCertList
  714. }
  715. this.ServeJSON()
  716. }
  717. // @Title 新增准入范围 --基建类
  718. // @Description 新增准入范围 --基建类
  719. // @Success 200 {object} controllers.Request
  720. // @router /addbusiness [post]
  721. func (this *OilSupplierCertSubController) AddBusiness() {
  722. var model suppliercertsub.OilSupplierCertSub
  723. var err error
  724. var jsonblob = this.Ctx.Input.RequestBody
  725. json.Unmarshal(jsonblob, &model)
  726. model.CreateBy = this.User.Realname
  727. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  728. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  729. var submodel suppliercertsub.OilSupplierCertSub
  730. where_certsub := " SupplierCertId = " + utils.ToStr(model.SupplierCertId) + " and SupplierTypeCode = 02"
  731. where_certsub += " and SubClassId = '" + utils.ToStr(model.SubClassId) + "'"
  732. has := svc.GetEntityByWhere(OilSupplierCertSubName, where_certsub, &submodel)
  733. unitsvc := organize.GetOrganizeService(utils.DBE)
  734. unitid := unitsvc.GetMyUnitDepartmentId(this.User.DepartmentId)
  735. if !has {
  736. //添加到准入分类表中
  737. if unitid == "100000095" {
  738. model.CertSubStatus = "1"
  739. }
  740. _, err = svc.InsertEntityBytbl(OilSupplierCertSubName, &model)
  741. } else {
  742. model.Id = submodel.Id
  743. }
  744. var supplierCertModel suppliercert.OilSupplierCert
  745. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  746. svcCert.GetEntityById(model.SupplierCertId, &supplierCertModel)
  747. var supplierModel supplier.OilSupplier
  748. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  749. svcSupplier.GetEntityById(model.SupplierId, &supplierModel)
  750. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  751. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  752. var needList []supplierfile.FileList
  753. if model.SupplierTypeCode == "01" {
  754. // needList = filesvc.GetGoodsNeedFileList(model.SubClassId)
  755. } else if model.SupplierTypeCode == "02" {
  756. needList = filesvc.GetBasicNeedFileList(strconv.Itoa(model.SubClassId))
  757. } else {
  758. // needList = filesvc.GetTechNeedFileList(model.SubClassId)
  759. }
  760. if supplierCertModel.InStyle == "4" {
  761. var needFile supplierfile.FileList
  762. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  763. needList = append(needList, needFile)
  764. }
  765. if err == nil {
  766. var list []supplierfile.OilSupplierFile
  767. where := "SupplierTypeCode in (02,000) and SupplierId = '" + strconv.Itoa(model.SupplierId) + "'"
  768. svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
  769. //三证合一或五证合一不需要的字段
  770. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  771. //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件,"
  772. // mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName")
  773. for i := 0; i < len(needList); i++ {
  774. if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了
  775. continue
  776. }
  777. var entity supplierfile.OilSupplierFile
  778. entity.SupplierId = model.SupplierId
  779. //加入对应表OilSupplierCert2File
  780. var cert2File suppliercertsub.OilSupplierCert2File //创建结构体
  781. cert2File.SupplierId = model.SupplierId
  782. cert2File.SupplierCertId = model.SupplierCertId
  783. cert2File.SupplierCertSubId = model.Id
  784. cert2File.SupplierTypeCode = model.SupplierTypeCode
  785. cert2File.SubClassId = model.SubClassId
  786. cert2File.Code = model.Code
  787. cert2File.Name = model.Name
  788. cert2File.NeedFileType = needList[i].FileName
  789. svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File)
  790. }
  791. }
  792. var errinfo ErrorDataInfo
  793. if err == nil {
  794. errinfo.Message = "操作成功!"
  795. errinfo.Code = 0
  796. errinfo.Item = model.Id
  797. this.Data["json"] = &errinfo
  798. this.ServeJSON()
  799. } else {
  800. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  801. errinfo.Code = -1
  802. this.Data["json"] = &errinfo
  803. this.ServeJSON()
  804. }
  805. }
  806. // @Title 删除准入范围
  807. // @Description
  808. // @Success 200 {object} ErrorInfo
  809. // @Failure 403 :id 为空
  810. // @router /businessdelete/:Id [delete]
  811. func (this *OilSupplierCertSubController) BusinessDelete() {
  812. Id := this.Ctx.Input.Param(":Id")
  813. //SupplierCertId := this.GetString("SupplierCertId")
  814. var errinfo ErrorInfo
  815. if Id == "" {
  816. errinfo.Message = "操作失败!请求信息不完整"
  817. errinfo.Code = -2
  818. this.Data["json"] = &errinfo
  819. this.ServeJSON()
  820. return
  821. }
  822. //根据Id查出OilSupplierCertSub的SubClassId
  823. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) //获得数据库引擎
  824. where := "delete from " + OilSupplierCertSubName + " where Id in (" + Id + ")" // 没有删除的准入范围
  825. whereCert2File := "delete from " + OilSupplierCert2FileName + " where SupplierCertSubId in (" + Id + ")" // 没有删除的准入范围
  826. svc.DBE.Exec(where)
  827. svc.DBE.Exec(whereCert2File)
  828. errinfo.Message = "删除成功!"
  829. errinfo.Code = 0
  830. this.Data["json"] = &errinfo
  831. this.ServeJSON()
  832. }
  833. // @Title 获取待审核业务列表
  834. // @Description get user by token
  835. // @Success 200 {object} models.Userblood
  836. // @router /auditbuslist [get]
  837. func (this *OilSupplierCertSubController) AuditbusList() {
  838. var list []suppliercertsub.OilSupplierCertSub
  839. //获取分页信息
  840. page := this.GetPageInfoForm()
  841. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  842. orderby := "CreateOn desc"
  843. Order := this.GetString("Order")
  844. Prop := this.GetString("Prop")
  845. if Order != "" && Prop != "" {
  846. orderby = Prop + " " + Order
  847. }
  848. where := "1 = 1"
  849. SupplierCertId := this.GetString("SupplierCertId")
  850. if SupplierCertId != "" {
  851. where = where + " and a.SupplierCertId = '" + SupplierCertId + "'"
  852. }
  853. total, list := svc.GetWaitAuditBusinesslist(page.CurrentPage, page.Size, orderby, OilSupplierCertSubName, OilClassOrgSettingName, where)
  854. var datainfo DataInfo
  855. datainfo.Items = list
  856. datainfo.CurrentItemCount = total
  857. this.Data["json"] = &datainfo
  858. this.ServeJSON()
  859. }
  860. // @Title 获取审核意见列表
  861. // @Description 获取审核意见列表
  862. // @Success 200 {object} controllers.Request
  863. // @router /opinionlist [get]
  864. func (this *OilSupplierCertSubController) OpinionList() {
  865. SupplierCertSubId := this.GetString("SupplierCertSubId")
  866. var list []suppliercertsub.OilSupplierOpinion
  867. where := " 1 = 1 "
  868. if SupplierCertSubId != "" {
  869. where = where + " and SupplierCertSubId = '" + SupplierCertSubId + "'"
  870. }
  871. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  872. svc.GetEntitysByWhere(OilSupplierOpinionName, where, &list)
  873. var datainfo DataInfo
  874. datainfo.Items = list
  875. this.Data["json"] = &datainfo
  876. this.ServeJSON()
  877. }
  878. // @Title 新增审核意见
  879. // @Description 新增审核意见
  880. // @Success 200 {object} controllers.Request
  881. // @router /addopinion [post]
  882. func (this *OilSupplierCertSubController) AddOpinion() {
  883. var model suppliercertsub.OilSupplierOpinion
  884. var jsonblob = this.Ctx.Input.RequestBody
  885. json.Unmarshal(jsonblob, &model)
  886. model.AuditorName = this.User.Realname
  887. model.AuditorId, _ = utils.StrTo(this.User.Id).Int()
  888. model.CreateBy = this.User.Realname
  889. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  890. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  891. //where := "SupplierCertSubId=" + strconv.Itoa(model.SupplierCertSubId) + " and AuditorId= " + strconv.Itoa(model.AuditorId) + " and Status = '" + model.Status + "'"
  892. //svc.DeleteEntityBytbl(OilSupplierOpinionName, where)
  893. _, err := svc.InsertEntityBytbl(OilSupplierOpinionName, &model)
  894. var errinfo ErrorDataInfo
  895. if err == nil {
  896. errinfo.Message = "操作成功!"
  897. errinfo.Code = 0
  898. errinfo.Item = model.Id
  899. this.Data["json"] = &errinfo
  900. this.ServeJSON()
  901. } else {
  902. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  903. errinfo.Code = -1
  904. this.Data["json"] = &errinfo
  905. this.ServeJSON()
  906. }
  907. }
  908. // @Title 更新准入项状态
  909. // @Description
  910. // @router /updatestatus/:Id/:Status [get]
  911. func (this *OilSupplierCertSubController) UpdateStatus() {
  912. Id := this.Ctx.Input.Param(":Id")
  913. Status := this.Ctx.Input.Param(":Status")
  914. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  915. var error error
  916. if Status == "1" {
  917. _, error = svc.DBE.Exec("update " + OilSupplierCertSubName + " set CertSubStatus='2' where Id=" + Id + "")
  918. } else {
  919. _, error = svc.DBE.Exec("update " + OilSupplierCertSubName + " set CertSubStatus='1' where Id=" + Id + "")
  920. }
  921. var errinfo ErrorDataInfo
  922. if error == nil {
  923. errinfo.Message = "操作成功!"
  924. errinfo.Code = 0
  925. this.Data["json"] = &errinfo
  926. this.ServeJSON()
  927. } else {
  928. errinfo.Message = "操作失败!"
  929. errinfo.Code = -1
  930. this.Data["json"] = &errinfo
  931. this.ServeJSON()
  932. }
  933. }
  934. // @Title 修改是否为供应商
  935. // @Description
  936. // @router /modify-manufacturer/:id [post]
  937. func (this *OilSupplierCertSubController) SetManufacturer() {
  938. certSubId, error := strconv.Atoi(this.Ctx.Input.Param(":id"))
  939. var manufacturerChangeDTO suppliercertsub.ManufacturerChangeDTO
  940. var jsonblob = this.Ctx.Input.RequestBody
  941. json.Unmarshal(jsonblob, &manufacturerChangeDTO)
  942. manufacturerChangeDTO.CertSubIdList = [] int{certSubId}
  943. invalidCertMsg := setManufacturerHandler(manufacturerChangeDTO)
  944. var errinfo ErrorDataInfo
  945. if error == nil && invalidCertMsg == "" {
  946. errinfo.Message = "修改成功!"
  947. errinfo.Code = 0
  948. this.Data["json"] = &errinfo
  949. this.ServeJSON()
  950. } else {
  951. errinfo.Message = "修改失败!" + invalidCertMsg
  952. errinfo.Code = -1
  953. this.Data["json"] = &errinfo
  954. this.ServeJSON()
  955. }
  956. }
  957. // @Title 批量修改是否为供应商
  958. // @Description
  959. // @router /modify-manufacturers/:certid [post]
  960. func (this *OilSupplierCertSubController) UpdateManufacturers() {
  961. certId := this.Ctx.Input.Param(":certid")
  962. var manufacturerChangeDTO suppliercertsub.ManufacturerChangeDTO
  963. var jsonblob = this.Ctx.Input.RequestBody
  964. json.Unmarshal(jsonblob, &manufacturerChangeDTO)
  965. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  966. var CertSublListAll []suppliercertsub.OilSupplierCertSub
  967. where := "SupplierCertId=" + certId
  968. svc.GetEntities(&CertSublListAll, where)
  969. certSubIdList := []int{}
  970. for _, certSub := range CertSublListAll {
  971. certSubIdList = append(certSubIdList, certSub.Id)
  972. }
  973. manufacturerChangeDTO.CertSubIdList = certSubIdList
  974. invalidCertMsg := setManufacturerHandler(manufacturerChangeDTO)
  975. var errinfo ErrorDataInfo
  976. if invalidCertMsg == "" {
  977. errinfo.Message = "修改成功!"
  978. errinfo.Code = 0
  979. this.Data["json"] = &errinfo
  980. this.ServeJSON()
  981. } else {
  982. errinfo.Message = invalidCertMsg
  983. errinfo.Code = -1
  984. this.Data["json"] = &errinfo
  985. this.ServeJSON()
  986. }
  987. }
  988. func setManufacturerHandler(manufacturerChangeDTO suppliercertsub.ManufacturerChangeDTO) (invalidCertMsg string) {
  989. CertSubIdList := manufacturerChangeDTO.CertSubIdList
  990. IsManufacturer := manufacturerChangeDTO.IsManufacturer
  991. SupplierId := manufacturerChangeDTO.SupplierId
  992. SupplierCertId := manufacturerChangeDTO.SupplierCertId
  993. //物资类
  994. SupplierTypeCode := "01"
  995. // 供应商主表
  996. svcSupplier := supplier.GetOilSupplierService(utils.DBE)
  997. var supplierEntity supplier.OilSupplier
  998. svcSupplier.GetEntityById(SupplierId, &supplierEntity)
  999. // 供应商准入申请表
  1000. svcCert := suppliercert.GetOilSupplierCertService(utils.DBE)
  1001. var certEntity suppliercert.OilSupplierCert
  1002. svcCert.GetEntityById(SupplierCertId, &certEntity)
  1003. //------ 查询出企业已有哪些资质 Start------------
  1004. var tableheaderList []tableheader.BaseTableheader
  1005. fileSql := "SELECT b.* from OilSupplierFile a LEFT JOIN Base_TableHeader b on a.NeedFileType=b.Name AND "
  1006. fileSql += " a.SupplierTypeCode=b.CategoryCode WHERE a.SupplierId='" + strconv.Itoa(SupplierId) + "'"
  1007. fileSql += " AND (a.SupplierTypeCode='" + SupplierTypeCode + "' or a.SupplierTypeCode='000')"
  1008. svcHeader := tableheader.GetTableHeaderService(utils.DBE)
  1009. svcHeader.DBE.SQL(fileSql).Find(&tableheaderList)
  1010. var companyHasHeaders string
  1011. for _, tableheader := range tableheaderList {
  1012. companyHasHeaders += tableheader.Name + ","
  1013. }
  1014. //------ 查询出企业已有哪些资质 End--------------
  1015. for _, certSubId := range CertSubIdList {
  1016. // 当前修改的记录
  1017. var certSubEntity suppliercertsub.OilSupplierCertSub
  1018. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  1019. svc.DBE.Where("Id=" + strconv.Itoa(certSubId)).Get(&certSubEntity)
  1020. //--------------取出准入项需要的资质 Start--------------------------
  1021. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  1022. filesvc := supplierfile.GetSupplierfileService(utils.DBE)
  1023. needList := filesvc.GetGoodsNeedFileList(strconv.Itoa(certSubId), strconv.Itoa(IsManufacturer)) // 需要的资质
  1024. //三证合一或五证合一不需要的字段
  1025. mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName")
  1026. if certEntity.InStyle == "4" {
  1027. var needFile supplierfile.FileList
  1028. //战略合作协议扫描件
  1029. needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  1030. needList = append(needList, needFile)
  1031. }
  1032. if certSubEntity.IsManufacturer == 1 { //制造商
  1033. var needFile supplierfile.FileList
  1034. // 中油集团公司产品质量认可证书
  1035. CNPCrenkezhengshu := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CNPCrenkezhengshu")
  1036. needFile.FileName = CNPCrenkezhengshu
  1037. needList = append(needList, needFile)
  1038. }
  1039. //--------------取出准入项需要的资质 End--------------------------
  1040. //--------------检查是否符合资质 Start--------------------------
  1041. certsValid := true
  1042. for _, needHeader := range needList {
  1043. if (supplierEntity.CredentialFlag == "1" || supplierEntity.CredentialFlag == "2") &&
  1044. strings.Contains(mergerCertSkipField, needHeader.FileName+",") {
  1045. //三证合一或五证合一的证件,不需要验证了
  1046. continue
  1047. }
  1048. if !strings.Contains(companyHasHeaders, needHeader.FileName+",") {
  1049. //缺少资质,不会保存
  1050. invalidCertMsg += certSubEntity.Code + " " + certSubEntity.Name + "(缺少:" + needHeader.FileName + ") ,"
  1051. certsValid = false
  1052. break
  1053. }
  1054. }
  1055. if !certsValid {
  1056. //缺少资质,不能修改
  1057. continue
  1058. }
  1059. //--------------检查是否符合资质 End--------------------------
  1060. //修改状态
  1061. certSubEntity.IsManufacturer = IsManufacturer
  1062. svc.DBE.Where("Id=" + strconv.Itoa(certSubId)).Update(&certSubEntity)
  1063. }
  1064. return invalidCertMsg
  1065. }
  1066. type OilSupplierCert2File struct {
  1067. Id int `json:"not null pk autoincr INT(10)"`
  1068. certSubId int `json:"not null default 0 comment('供方基本信息表主键') INT(10)"`
  1069. certSubStatus int `json:"not null default 0 comment('供方准入证书信息表主键') INT(10)"`
  1070. stopReason string `json:"not null default '0' comment('准入类别代码(1 物资类,2 基建类,3 技术服务类)') VARCHAR(5)"`
  1071. }
  1072. type LostCertFiles struct {
  1073. Code string
  1074. Name string
  1075. CertFileName string
  1076. }
  1077. // @Title 记录准入项状态更改日志
  1078. // @Description
  1079. // @router /updatestatuswithlog/:Id [post]
  1080. func (this *OilSupplierCertSubController) UpdateStatusWithLog() {
  1081. Id := this.Ctx.Input.Param(":Id")
  1082. reasonSvc := supplierpausereason.GetOilSupplierPauseReasonService(utils.DBE)
  1083. var pauseModel supplierpausereason.OilSupplierPauseReason
  1084. var jsonblob = this.Ctx.Input.RequestBody
  1085. json.Unmarshal(jsonblob, &pauseModel)
  1086. Status := pauseModel.CertSubStatus
  1087. svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
  1088. var error error
  1089. if Status == "1" {
  1090. _, error = svc.DBE.Exec("update " + OilSupplierCertSubName + " set CertSubStatus='2' where Id=" + Id + "")
  1091. pauseModel.CertSubStatus = "2"
  1092. } else {
  1093. _, error = svc.DBE.Exec("update " + OilSupplierCertSubName + " set CertSubStatus='1' where Id=" + Id + "")
  1094. pauseModel.CertSubStatus = "1"
  1095. }
  1096. pauseModel.CreateOn = time.Now()
  1097. pauseModel.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1098. pauseModel.CreateBy = this.User.Realname
  1099. reasonSvc.InsertEntity(pauseModel)
  1100. var errinfo ErrorDataInfo
  1101. if error == nil {
  1102. errinfo.Message = "操作成功!"
  1103. errinfo.Code = 0
  1104. this.Data["json"] = &errinfo
  1105. this.ServeJSON()
  1106. } else {
  1107. errinfo.Message = "操作失败!"
  1108. errinfo.Code = -1
  1109. this.Data["json"] = &errinfo
  1110. this.ServeJSON()
  1111. }
  1112. }