2
3

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