package oilsupplier import ( "dashoo.cn/backend/api/business/oilsupplier/goodsaptitude" "dashoo.cn/backend/api/business/oilsupplier/supplier" "dashoo.cn/backend/api/business/oilsupplier/suppliercert" "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub" "dashoo.cn/backend/api/business/oilsupplier/supplierfile" "dashoo.cn/business2/parameter" "encoding/json" "fmt" "log" "reflect" "strconv" "strings" "time" "dashoo.cn/backend/api/business/oilsupplier/suppliercertappendsub" . "dashoo.cn/backend/api/controllers" "dashoo.cn/utils" ) type OilSupplierCertAppendSubController struct { BaseController } type AppendChangeItemsAll struct { InfochangeForm []appenditems SupplierId string MInfoId string } type appenditems struct { SelectItem string SelectItemName string BeChangeInfo string ChangeInfo string } // @Title 获取列表 // @Description 获取列表 // @Success 200 {object} []suppliercertappendsub.OilSupplierCertAppendSub // @router /getList [get] func (this *OilSupplierCertAppendSubController) GetList() { //获取分页信息 page := this.GetPageInfoForm() //where := " 1=1 " //orderby := "Id" //asc := false //Order := this.GetString("Order") //Prop := this.GetString("Prop") //if Order != "" && Prop != "" { // orderby = Prop // if Order == "asc" { // asc = true // } //} //SupplierCertAppendId := this.GetString("SupplierCertAppendId") //if SupplierCertAppendId != "" { // where = where + " and SupplierCertAppendId = " + SupplierCertAppendId //} SupplierCertId := this.GetString("SupCertId") SupplierTypeCode := this.GetString("SupTypeCode") suwhere := " SupplierCertId = " + SupplierCertId + " and SupplierTypeCode = " + SupplierTypeCode svc := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE) var list []suppliercertsub.OilSupplierCertSub //svc.GetEntitysByWhere(OilSupplierCertAppendSubName, where, &list) //svc.GetEntitysByOrderbyWhere(OilSupplierCertSubName, suwhere, "CreateOn asc", &list) total := svc.GetPagingEntitiesWithOrder(page.CurrentPage, page.Size, "CreateOn", false, &list, suwhere) var dataInfo DataInfo dataInfo.CurrentItemCount = total dataInfo.PageIndex = page.CurrentPage dataInfo.ItemsPerPage = page.Size dataInfo.Items = list this.Data["json"] = &dataInfo this.ServeJSON() } // @Title 获取列表 // @Description 获取列表 // @Success 200 {object} []suppliercertappendsub.OilSupplierCertAppendSub // @router /getListInandApp [get] func (this *OilSupplierCertAppendSubController) GetListInAndApp() { //获取分页信息 page := this.GetPageInfoForm() //where := " 1=1 " //orderby := "Id" //asc := false //Order := this.GetString("Order") //Prop := this.GetString("Prop") //if Order != "" && Prop != "" { // orderby = Prop // if Order == "asc" { // asc = true // } //} //SupplierCertAppendId := this.GetString("SupplierCertAppendId") //if SupplierCertAppendId != "" { // where = where + " and SupplierCertAppendId = " + SupplierCertAppendId //} SupplierCertId := this.GetString("SupCertId") SupplierTypeCode := this.GetString("SupTypeCode") SupplierCertAppendId := this.GetString("SupplierCertAppendId") searchCode := this.GetString("searchCode") where := `((SupplierCertId = ` + SupplierCertId + ` AND SupplierTypeCode = '` + SupplierTypeCode + `' AND TYPE IN ('1', '3')) OR (SupplierCertId = ` + SupplierCertId + ` AND SupplierTypeCode = '` + SupplierTypeCode + `' AND SupplierCertAppendId = ` + SupplierCertAppendId + `)) ` //" SupplierCertId = "+ SupplierCertId+ " and SupplierTypeCode = "+ SupplierTypeCode if searchCode != "" { where += " and (Code like '" + strings.Trim(searchCode, " ") + "%' or Name like '%" + strings.Trim(searchCode, " ") + "%')" } svc := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE) var list []suppliercertsub.OilSupplierCertSub //svc.GetEntitysByWhere(OilSupplierCertAppendSubName, where, &list) //svc.GetEntitysByOrderbyWhere(OilSupplierCertSubName, suwhere, "CreateOn asc", &list) total := svc.GetPagingEntitiesWithOrder(page.CurrentPage, page.Size, "CreateOn", false, &list, where) var dataInfo DataInfo if list == nil { dataInfo.Items = []suppliercertsub.OilSupplierCertSub{} } else { dataInfo.Items = list } dataInfo.CurrentItemCount = total dataInfo.PageIndex = page.CurrentPage dataInfo.ItemsPerPage = page.Size this.Data["json"] = &dataInfo this.ServeJSON() } // @Title 获取列表 // @Description 获取列表 // @Success 200 {object} []suppliercertappendsub.OilSupplierCertAppendSub // @router /getMyList [get] func (this *OilSupplierCertAppendSubController) GetMyList() { //获取分页信息 page := this.GetPageInfoForm() SupplierCertId := this.GetString("SupCertId") SupplierTypeCode := this.GetString("SupTypeCode") SuppAppendId := this.GetString("SupplierCertAppendId") searchCode := this.GetString("searchCode") where := " SupplierCertId = " + SupplierCertId + " and SupplierTypeCode = '" + SupplierTypeCode + "' and SupplierCertAppendId = " + SuppAppendId if searchCode != "" { where += " and (Code like '" + strings.Trim(searchCode, " ") + "%' or Name like '%" + strings.Trim(searchCode, " ") + "%')" } svc := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE) var list []suppliercertsub.OilSupplierCertSub //svc.GetEntitysByOrderbyWhere(OilSupplierCertSubName, suwhere, "CreateOn asc", &list) total := svc.GetPagingEntitiesWithOrder(page.CurrentPage, page.Size, "CreateOn", false, &list, where) var dataInfo DataInfo if list == nil { dataInfo.Items = []suppliercertsub.OilSupplierCertSub{} } else { dataInfo.Items = list } dataInfo.CurrentItemCount = total dataInfo.PageIndex = page.CurrentPage dataInfo.ItemsPerPage = page.Size this.Data["json"] = &dataInfo this.ServeJSON() } // @Title 获取列表 // @Description 获取列表 // @Success 200 {object} []suppliercertappendsub.OilSupplierCertAppendSub // @router /getListappend [get] func (this *OilSupplierCertAppendSubController) GetListAppend() { //获取分页信息 page := this.GetPageInfoForm() //where := " 1=1 " //orderby := "Id" //asc := false //Order := this.GetString("Order") //Prop := this.GetString("Prop") //if Order != "" && Prop != "" { // orderby = Prop // if Order == "asc" { // asc = true // } //} //SupplierCertAppendId := this.GetString("SupplierCertAppendId") //if SupplierCertAppendId != "" { // where = where + " and SupplierCertAppendId = " + SupplierCertAppendId //} SupplierCertAppendId := this.GetString("SupplierCertAppendId") SupplierCertId := this.GetString("SupCertId") SupplierTypeCode := this.GetString("SupTypeCode") searchCode := this.GetString("searchCode") where := " SupplierCertId = " + SupplierCertId + " and SupplierCertAppendId= " + SupplierCertAppendId + " and SupplierTypeCode = '" + SupplierTypeCode + "' and Type in(2,3) " if searchCode != "" { where += " and (Code like '" + strings.Trim(searchCode, " ") + "%' or Name like '%" + strings.Trim(searchCode, " ") + "%')" } svc := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE) var list []suppliercertsub.OilSupplierCertSub //svc.GetEntitysByWhere(OilSupplierCertAppendSubName, where, &list) //svc.GetEntitysByOrderbyWhere(OilSupplierCertSubName, suwhere, "CreateOn asc", &list) total := svc.GetPagingEntitiesWithOrder(page.CurrentPage, page.Size, "CreateOn", false, &list, where) var dataInfo DataInfo if list == nil { dataInfo.Items = []suppliercertsub.OilSupplierCertSub{} } else { dataInfo.Items = list } dataInfo.CurrentItemCount = total dataInfo.PageIndex = page.CurrentPage dataInfo.ItemsPerPage = page.Size this.Data["json"] = &dataInfo this.ServeJSON() } // @Title 添加 // @Description 添加增项分类信息基建类 // @Success 200 {object} controllers.Request // @router /addappendsub [post] func (this *OilSupplierCertAppendSubController) AddAppendSub() { var model suppliercertsub.OilSupplierCertSub var err error var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) model.CreateBy = this.User.Realname model.CreateUserId, _ = utils.StrTo(this.User.Id).Int() model.CertSubStatus = "-1" svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) var submodel suppliercertsub.OilSupplierCertSub where_certsub := " SupplierCertId = " + utils.ToStr(model.SupplierCertId) + " and SupplierTypeCode = 02" where_certsub += " and SubClassId = '" + utils.ToStr(model.SubClassId) + "'" has := svc.GetEntityByWhere(OilSupplierCertSubName, where_certsub, &submodel) if !has { //添加到准入分类表中 _, err = svc.InsertEntityBytbl(OilSupplierCertSubName, &model) // TODO: 删除准入范围和资质对应关系表 /*var supplierCertModel suppliercert.OilSupplierCert svcCert := suppliercert.GetOilSupplierCertService(utils.DBE) svcCert.GetEntityById(model.SupplierCertId, &supplierCertModel) var supplierModel supplier.OilSupplier svcSupplier := supplier.GetOilSupplierService(utils.DBE) svcSupplier.GetEntityById(model.SupplierId, &supplierModel) paramSvc := baseparameter.GetBaseparameterService(utils.DBE) filesvc := supplierfile.GetSupplierfileService(utils.DBE) var needList []supplierfile.FileList if model.SupplierTypeCode == "01" { // needList = filesvc.GetGoodsNeedFileList(model.SubClassId) } else if model.SupplierTypeCode == "02" { needList = filesvc.GetBasicNeedFileList(strconv.Itoa(model.SubClassId)) } else { // needList = filesvc.GetTechNeedFileList(model.SubClassId) } if supplierCertModel.InStyle == "4" { var needFile supplierfile.FileList needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile") needList = append(needList, needFile) } if err == nil { var list []supplierfile.OilSupplierFile where := "SupplierTypeCode in (02,000) and SupplierId = '" + strconv.Itoa(model.SupplierId) + "'" svc.GetEntitysByWhere(OilSupplierFileName, where, &list) //三证合一或五证合一不需要的字段 mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName") //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件," // mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName") for i := 0; i < len(needList); i++ { if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了 continue } var entity supplierfile.OilSupplierFile entity.SupplierId = model.SupplierId //加入对应表OilSupplierCert2File var cert2File suppliercertsub.OilSupplierCert2File //创建结构体 cert2File.SupplierId = model.SupplierId cert2File.SupplierCertId = model.SupplierCertId cert2File.SupplierCertSubId = model.Id cert2File.SupplierTypeCode = model.SupplierTypeCode cert2File.SubClassId = model.SubClassId cert2File.Code = model.Code cert2File.Name = model.Name cert2File.NeedFileType = needList[i].FileName svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File) } }*/ } var errinfo ErrorDataInfo if err == nil { errinfo.Message = "操作成功!" errinfo.Code = 0 errinfo.Item = model.Id this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 批量添加增项准入范围--技术服务类 // @Description 批量添加准入范围 // @Success 200 {object} business.device.DeviceChannels // @router /addtechbus [post] func (this *OilSupplierCertAppendSubController) AddTechBus() { var jsonblob = this.Ctx.Input.RequestBody var datamain suppliercertsub.OilSupplierCertSub var dataother suppliercertsub.TechnologySubModel json.Unmarshal(jsonblob, &datamain) json.Unmarshal(jsonblob, &dataother) var supplierCertModel suppliercert.OilSupplierCert svcCert := suppliercert.GetOilSupplierCertService(utils.DBE) svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel) var supplierModel supplier.OilSupplier svcSupplier := supplier.GetOilSupplierService(utils.DBE) svcSupplier.GetEntityById(datamain.SupplierId, &supplierModel) for n := 0; n < len(dataother.CheckList); n++ { where_sub := "SupplierTypeCode = 03 and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'" where_sub += " and SupplierCertId = '" + strconv.Itoa(dataother.SupplierCertId) + "'" where_sub += " and SubClassId = '" + strconv.Itoa(dataother.CheckList[n].Id) + "'" var model suppliercertsub.OilSupplierCertSub svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) has := svc.GetEntityByWhere(OilSupplierCertSubName, where_sub, &model) if !has { // TODO: 不存在的准入范围直接就新增了,因为前台已经调用了checkLost检查过是否缺少资质,有时间可以在些方法补充验证 datamain.SubClassId = dataother.CheckList[n].Id datamain.Code = dataother.CheckList[n].Code datamain.Name = dataother.CheckList[n].Name datamain.Remark = dataother.Remark datamain.CertSubStatus = "-1" datamain.IsDelete = 0 datamain.CreateBy = this.User.Realname datamain.CreateUserId, _ = utils.StrTo(this.User.Id).Int() datamain.Id = 0 svc.InsertEntityBytbl(OilSupplierCertSubName, &datamain) // TODO: 删除准入范围和资质对应关系表 /*paramSvc := baseparameter.GetBaseparameterService(utils.DBE) filesvc := supplierfile.GetSupplierfileService(utils.DBE) needList := filesvc.GetTechNeedFileList(strconv.Itoa(dataother.CheckList[n].Id)) if supplierCertModel.InStyle == "4" { var needFile supplierfile.FileList needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile") needList = append(needList, needFile) } var list []supplierfile.OilSupplierFile where := "SupplierTypeCode in (03,000) and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'" svc.GetEntitysByWhere(OilSupplierFileName, where, &list) //三证合一或五证合一不需要的字段 mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName") //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件," // mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName") for i := 0; i < len(needList); i++ { var entity supplierfile.OilSupplierFile entity.SupplierId = dataother.SupplierId if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了 continue } //加入对应表OilSupplierCert2File var cert2File suppliercertsub.OilSupplierCert2File //创建结构体 cert2File.SupplierId = dataother.SupplierId cert2File.SupplierCertId = dataother.SupplierCertId cert2File.SupplierCertSubId = datamain.Id cert2File.SupplierTypeCode = dataother.SupplierTypeCode cert2File.SubClassId= dataother.CheckList[n].Id cert2File.Code = dataother.CheckList[n].Code cert2File.Name = dataother.CheckList[n].Name cert2File.NeedFileType = needList[i].FileName svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File) }*/ } } var errinfo ErrorDataInfo errinfo.Message = "操作成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } // @Title 批量添加增项准入范围--物资类 // @Description 批量添加增项准入范围 // @Success 200 {object} business.device.DeviceChannels // @router /addgoodsbus [post] func (this *OilSupplierCertAppendSubController) AddGoodsBus() { var jsonblob = this.Ctx.Input.RequestBody var datamain suppliercertsub.OilSupplierCertSub var dataother suppliercertsub.SupplierCertSubModel json.Unmarshal(jsonblob, &datamain) json.Unmarshal(jsonblob, &dataother) var supplierCertModel suppliercert.OilSupplierCert svcCert := suppliercert.GetOilSupplierCertService(utils.DBE) svcCert.GetEntityById(datamain.SupplierCertId, &supplierCertModel) var supplierModel supplier.OilSupplier svcSupplier := supplier.GetOilSupplierService(utils.DBE) svcSupplier.GetEntityById(datamain.SupplierId, &supplierModel) var goods goodsaptitude.GoodsBusiness1 svcGoods := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE) for n := 0; n < len(dataother.CheckList); n++ { svcGoods.GetEntityJoin2(OilGoodsAptitudeName, OilGoodsAptitudeClassName, &goods, "Code = '"+dataother.CheckList[n].Code+"'") where_sub := "SupplierTypeCode = 01 and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'" where_sub += " and SupplierCertId = '" + strconv.Itoa(dataother.SupplierCertId) + "'" where_sub += " and SubClassId = '" + strconv.Itoa(goods.Id) + "'" var model suppliercertsub.OilSupplierCertSub svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) has := svc.GetEntityByWhere(OilSupplierCertSubName, where_sub, &model) if !has { // TODO: 不存在的准入范围直接就新增了,因为前台已经调用了checkLost检查过是否缺少资质,有时间可以在些方法补充验证 datamain.SubClassId = goods.Id datamain.Code = dataother.CheckList[n].Code datamain.Name = dataother.CheckList[n].Name datamain.GoodsLevel = goods.GoodsLevel datamain.CertSubStatus = "-1" datamain.Remark = dataother.Remark datamain.IsDelete = 0 datamain.CreateBy = this.User.Realname datamain.CreateUserId, _ = utils.StrTo(this.User.Id).Int() datamain.Id = 0 log.Print("增项【可】添加不存在的准入范围,SupplierId: " + strconv.Itoa(datamain.SupplierId) + "AppendId: " + strconv.Itoa(datamain.SupplierCertAppendId) + "Code: " + datamain.Code) svc.InsertEntityBytbl(OilSupplierCertSubName, &datamain) log.Println("添加成功") // TODO: 删除准入范围和资质对应关系表 /*paramSvc := baseparameter.GetBaseparameterService(utils.DBE) filesvc := supplierfile.GetSupplierfileService(utils.DBE) needList := filesvc.GetGoodsNeedFileList(dataother.CheckList[n].Id,"2") if supplierCertModel.InStyle == "4" { var needFile supplierfile.FileList //战略合作协议扫描件 needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile") needList = append(needList, needFile) } var list []supplierfile.OilSupplierFile where := "SupplierTypeCode in (01,000) and IsManuf in ('0','2') and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'" svc.GetEntitysByWhere(OilSupplierFileName, where, &list) //三证合一或五证合一不需要的字段 mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName") //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件," // mustField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName") for i := 0; i < len(needList); i++ { var entity supplierfile.OilSupplierFile entity.SupplierId = dataother.SupplierId if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了 continue } //加入对应表OilSupplierCert2File var cert2File suppliercertsub.OilSupplierCert2File //创建结构体 cert2File.SupplierId = dataother.SupplierId cert2File.SupplierCertId = dataother.SupplierCertId cert2File.SupplierCertSubId = datamain.Id cert2File.SupplierTypeCode = dataother.SupplierTypeCode cert2File.SubClassId, _ = utils.StrTo(dataother.CheckList[n].Id).Int() cert2File.IsManuf = "2" cert2File.Code = dataother.CheckList[n].Code cert2File.Name = dataother.CheckList[n].Name cert2File.NeedFileType = needList[i].FileName svc.InsertEntityBytbl(OilSupplierCert2FileName, &cert2File) }*/ } else { log.Print("增项【不可】再次添加已添加过的准入范围,SupplierId: " + strconv.Itoa(datamain.SupplierId) + "AppendId: " + strconv.Itoa(datamain.SupplierCertAppendId) + "Code: " + datamain.Code) } } var errinfo ErrorDataInfo errinfo.Message = "操作成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } // @Title 修改实体 // @Description 修改实体 // @Success 200 {object} controllers.Request // @router /update/:id [post] func (this *OilSupplierCertAppendSubController) UpdateEntity() { var errinfo ErrorInfo var model suppliercertappendsub.OilSupplierCertAppendSub id := this.Ctx.Input.Param(":id") if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } svc := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE) var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &model) model.ModifiedOn = time.Now() model.ModifiedBy = this.User.Realname model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int() cols := []string{ "SortFlag", "Code", "Name", "Remark", "ModifiedOn", "ModifiedUserId", "ModifiedBy", } err := svc.UpdateEntityBytbl(OilSupplierCertAppendSubName, id, &model, cols) if err == nil { errinfo.Message = "修改成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 删除 // @Description 删除信息 // @Success 200 {object} ErrorInfo // @Failure 403 :id 为空 // @router /delete/:Id [delete] func (this *OilSupplierCertAppendSubController) DeleteEntity() { Id := this.Ctx.Input.Param(":Id") var errinfo ErrorInfo if Id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var model suppliercertappendsub.OilSupplierCertAppendSub var entityempty suppliercertappendsub.OilSupplierCertAppendSub svc := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE) opdesc := "删除-" + Id err := svc.DeleteOperationAndWriteLogBytbl(OilSupplierCertAppendSubName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "增项分类") if err == nil { errinfo.Message = "删除成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 修改是否为供应商 // @Description // @router /updatemanufacturerappend/:Id/:SupplierId/:IsManufacturer [get] func (this *OilSupplierCertAppendSubController) UpdateManufacturerAppend() { Id := this.Ctx.Input.Param(":Id") IsManufacturer := this.Ctx.Input.Param(":IsManufacturer") SupplierId := this.Ctx.Input.Param(":SupplierId") SupplierTypeCode := "01" svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE) var CertSublList []suppliercertsub.OilSupplierCertSub where := "SupplierId=" + SupplierId + " and Id not in (" + Id + ") and SupplierTypeCode ='" + SupplierTypeCode + "'" // 没有删除的准入范围 svc.GetEntities(&CertSublList, where) var SupplierCertId int for _, CertSub := range CertSublList { SupplierCertId = CertSub.SupplierCertId } var supplierCertModel suppliercert.OilSupplierCert svcCert := suppliercert.GetOilSupplierCertService(utils.DBE) svcCert.GetEntityById(SupplierCertId, &supplierCertModel) var supplierModel supplier.OilSupplier svcSupplier := supplier.GetOilSupplierService(utils.DBE) svcSupplier.GetEntityById(SupplierId, &supplierModel) var error error if IsManufacturer == "2" { var errinfo ErrorInfo //根据Id查出OilSupplierCertSub的SubClassId filesvc := supplierfile.GetSupplierfileService(utils.DBE) paramSvc := baseparameter.GetBaseparameterService(utils.DBE) SubClassIds := "" for _, CertSub := range CertSublList { SubClassIds += strconv.Itoa(CertSub.SubClassId) + "," } var SurplusList []supplierfile.FileList SubClassIds = strings.Trim(SubClassIds, ",") if SubClassIds != "" { if SupplierTypeCode == "01" { var CertSublList2 []suppliercertsub.OilSupplierCertSub wheregood := "SupplierId=" + SupplierId + " and Id not in (" + Id + ") and SupplierTypeCode =" + SupplierTypeCode + " and IsManufacturer =" + IsManufacturer // 没有删除的准入范围 svc.GetEntities(&CertSublList2, wheregood) SubClassIds2 := "" for _, CertSub := range CertSublList2 { SubClassIds2 += strconv.Itoa(CertSub.SubClassId) + "," } SubClassIds2 = strings.Trim(SubClassIds2, ",") SurplusList = filesvc.GetGoodsNeedFileList(SubClassIds2, IsManufacturer) } } fileNames := "" for _, CertSub := range SurplusList { fileNames += CertSub.FileName + "," } var datamain suppliercertsub.OilSupplierCertSub //创建OilSupplierCertSub结构体(映射用) var datamain2 []suppliercertsub.OilSupplierCertSub //空的查询用 where = " Id= " + Id svc.GetEntity(&datamain, where) //根据Id查找,映射结构体 //再根据企业id查找这个企业有几个准入范围(如果只有一个准入范围了,基本资质也删除) supplierId := datamain.SupplierId where = "SupplierId=" + strconv.Itoa(supplierId) svc.GetEntities(&datamain2, where) flag := 0 if len(datamain2) == 1 { flag = 1 } subClassId := datamain.SubClassId //4.拿到结构体中的准入范围SubClassId //根据SubClassId查出此准入范围所拥有的资质名称 var needList []supplierfile.FileList //定义存储所拥有资质名称的数组 needList = filesvc.GetGoodsNeedFileList(strconv.Itoa(subClassId), IsManufacturer) //通过准入范围Id获得资质名称并填充数组 var mustField string mustField = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName") //必需的资质 //根据企业ID(SupplierId)和此准入范围所拥有的资质名称删除OilSupplierFile表中对应的资质 for j := 0; j < len(needList); j++ { //循环遍历资质名称数组,逐条删除 if flag == 0 && strings.Contains(mustField, needList[j].FileName+",") { continue } if flag == 0 && strings.Contains(fileNames, needList[j].FileName+",") { continue } where := " SupplierId= '" + strconv.Itoa(datamain.SupplierId) + "' and SupplierTypeCode =" + SupplierTypeCode + " and IsManuf='" + IsManufacturer + "' and NeedFileType='" + needList[j].FileName + "'" //拼接删除sql err := svc.DeleteEntityBytbl(OilSupplierFileName, where) //删除第j条资质数据 if err == nil { errinfo.Message = "删除成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } needList = filesvc.GetGoodsNeedFileList(strconv.Itoa(subClassId), "1") //if supplierCertModel.InStyle == "4" { // var needFile supplierfile.FileList // //战略合作协议扫描件 // needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile") // needList = append(needList, needFile) //} var list []supplierfile.OilSupplierFile where := "SupplierTypeCode in (01,000) and IsManuf in ('0','1') and SupplierId =" + strconv.Itoa(supplierId) svc.GetEntitysByWhere(OilSupplierFileName, where, &list) //三证合一或五证合一不需要的字段 mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName") //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件," mustField = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName") for i := 0; i < len(needList); i++ { var entity supplierfile.OilSupplierFile entity.SupplierId = supplierId if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了 continue } //加入对应表OilSupplierCertFile if strings.Contains(mustField, needList[i].FileName+",") { entity.SupplierTypeCode = "000" entity.IsManuf = "0" } else { entity.SupplierTypeCode = "01" entity.IsManuf = "1" } entity.NeedFileType = needList[i].FileName entity.FileType = 1 //entity.EffectDate = time.Now() entity.CreateBy = this.User.Realname entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int() entity.SupType = 2 entity.SupplierCertSubId = datamain.SupplierCertAppendId isRepeat := false for j := 0; j < len(list); j++ { if list[j].NeedFileType == needList[i].FileName { isRepeat = true break } } if isRepeat == true { continue } svc.InsertEntityBytbl(OilSupplierFileName, &entity) } _, error = svc.DBE.Exec("update " + OilSupplierCertSubName + " set IsManufacturer =1 where Id=" + Id + "") } else if IsManufacturer == "1" { var errinfo ErrorInfo //根据Id查出OilSupplierCertSub的SubClassId filesvc := supplierfile.GetSupplierfileService(utils.DBE) paramSvc := baseparameter.GetBaseparameterService(utils.DBE) SubClassIds := "" for _, CertSub := range CertSublList { SubClassIds += strconv.Itoa(CertSub.SubClassId) + "," } var SurplusList []supplierfile.FileList SubClassIds = strings.Trim(SubClassIds, ",") if SubClassIds != "" { if SupplierTypeCode == "01" { var CertSublList2 []suppliercertsub.OilSupplierCertSub wheregood := "SupplierId=" + SupplierId + " and Id not in (" + Id + ") and SupplierTypeCode =" + SupplierTypeCode + " and IsManufacturer =" + IsManufacturer // 没有删除的准入范围 svc.GetEntities(&CertSublList2, wheregood) SubClassIds2 := "" for _, CertSub := range CertSublList2 { SubClassIds2 += strconv.Itoa(CertSub.SubClassId) + "," } SubClassIds2 = strings.Trim(SubClassIds2, ",") SurplusList = filesvc.GetGoodsNeedFileList(SubClassIds2, IsManufacturer) } } fileNames := "" for _, CertSub := range SurplusList { fileNames += CertSub.FileName + "," } var datamain suppliercertsub.OilSupplierCertSub //创建OilSupplierCertSub结构体(映射用) var datamain2 []suppliercertsub.OilSupplierCertSub //空的查询用 where = " Id= " + Id svc.GetEntity(&datamain, where) //根据Id查找,映射结构体 //再根据企业id查找这个企业有几个准入范围(如果只有一个准入范围了,基本资质也删除) supplierId := datamain.SupplierId where = "SupplierId=" + strconv.Itoa(supplierId) svc.GetEntities(&datamain2, where) flag := 0 if len(datamain2) == 1 { flag = 1 } subClassId := datamain.SubClassId //4.拿到结构体中的准入范围SubClassId //根据SubClassId查出此准入范围所拥有的资质名称 var needList []supplierfile.FileList //定义存储所拥有资质名称的数组 needList = filesvc.GetGoodsNeedFileList(strconv.Itoa(subClassId), IsManufacturer) //通过准入范围Id获得资质名称并填充数组 var mustField string mustField = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName") //必需的资质 //根据企业ID(SupplierId)和此准入范围所拥有的资质名称删除OilSupplierFile表中对应的资质 for j := 0; j < len(needList); j++ { //循环遍历资质名称数组,逐条删除 if flag == 0 && strings.Contains(mustField, needList[j].FileName+",") { continue } if flag == 0 && strings.Contains(fileNames, needList[j].FileName+",") { continue } where := " SupplierId= '" + strconv.Itoa(datamain.SupplierId) + "' and SupplierTypeCode =" + SupplierTypeCode + " and IsManuf='" + IsManufacturer + "' and NeedFileType='" + needList[j].FileName + "'" //拼接删除sql err := svc.DeleteEntityBytbl(OilSupplierFileName, where) //删除第j条资质数据 if err == nil { errinfo.Message = "删除成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } needList = filesvc.GetGoodsNeedFileList(strconv.Itoa(subClassId), "2") //if supplierCertModel.InStyle == "4" { // var needFile supplierfile.FileList // //战略合作协议扫描件 // needFile.FileName = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile") // needList = append(needList, needFile) //} var list []supplierfile.OilSupplierFile where := "SupplierTypeCode in (01,000) and IsManuf in ('0','2') and SupplierId =" + strconv.Itoa(supplierId) svc.GetEntitysByWhere(OilSupplierFileName, where, &list) //三证合一或五证合一不需要的字段 mergerCertSkipField := paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MergerCertSkipFieldName") //"营业执照,组织代码,组织机构代码证,税务登记证,税务登记,开户许可,银行开户许可证,承诺书,诚信合规承诺书,企业信息系统截图,战略合作协议扫描件," mustField = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "MustFieldName") for i := 0; i < len(needList); i++ { var entity supplierfile.OilSupplierFile entity.SupplierId = supplierId if (supplierModel.CredentialFlag == "1" || supplierModel.CredentialFlag == "2") && strings.Contains(mergerCertSkipField, needList[i].FileName+",") { //三证合一或五证合一了 continue } //加入对应表OilSupplierCertFile if strings.Contains(mustField, needList[i].FileName+",") { entity.SupplierTypeCode = "000" entity.IsManuf = "0" } else { entity.SupplierTypeCode = "01" entity.IsManuf = "2" } entity.NeedFileType = needList[i].FileName entity.FileType = 1 //entity.EffectDate = time.Now() entity.CreateBy = this.User.Realname entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int() entity.SupType = 2 entity.SupplierCertSubId = datamain.SupplierCertAppendId isRepeat := false for j := 0; j < len(list); j++ { if list[j].NeedFileType == needList[i].FileName { isRepeat = true break } } if isRepeat == true { continue } svc.InsertEntityBytbl(OilSupplierFileName, &entity) } _, error = svc.DBE.Exec("update " + OilSupplierCertSubName + " set IsManufacturer=2 where Id=" + Id + "") } var errinfo ErrorDataInfo if error == nil { errinfo.Message = "修改成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "修改失败!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 获取实体 // @Description 获取实体 // @Success 200 {object} supplier.OilSupplier // @router /getchangelist/:id [get] func (this *OilSupplierCertAppendSubController) GetChangeEntity() { Id := this.Ctx.Input.Param(":id") InfoId := this.GetString("InfomainId") var models [2]supplier.OilSupplier var model supplier.OilSupplier var enumModel supplier.OilSupplier svc := supplier.GetOilSupplierService(utils.DBE) svc.GetEntityByIdBytbl(OilSupplierName, Id, &model) models[0] = model var infoitems []suppliercertappendsub.OilAppendChangeItem where := " SupplierId = " + Id + " and InfoId =" + InfoId where = where + " and ChangeStatus = 0" svc.GetEntitysByWhere(OilAppendChangeItemName, where, &infoitems) tmpModel := &model enumModel = *tmpModel immumodel := reflect.ValueOf(&enumModel) elem := immumodel.Elem() if len(infoitems) == 0 { models[1] = enumModel this.Data["json"] = &models this.ServeJSON() return } else { for _, info := range infoitems { fmt.Println(info.SelectItem) fmt.Println(";;;;;;;;;", elem.FieldByName(info.SelectItem).Type().String()) if elem.FieldByName(info.SelectItem).Type().String() == "int64" { intchangeinfo, _ := strconv.ParseInt(info.ChangeInfo, 10, 64) elem.FieldByName(info.SelectItem).SetInt(intchangeinfo) } else if elem.FieldByName(info.SelectItem).Type().String() == "float64" { floatchangeinfo, _ := strconv.ParseFloat(info.ChangeInfo, 64) elem.FieldByName(info.SelectItem).SetFloat(floatchangeinfo) } else if elem.FieldByName(info.SelectItem).Type().String() == "time.Time" { t, _ := time.Parse("2006-01-02", info.ChangeInfo[0:10]) elem.FieldByName(info.SelectItem).Set(reflect.ValueOf(t)) } else { elem.FieldByName(info.SelectItem).SetString(info.ChangeInfo) } } models[1] = enumModel this.Data["json"] = &models this.ServeJSON() } } // @Title 获取实体 // @Description 获取实体 // @Success 200 {object} annualaudit.OilAnnualAudit // @router /auditget/:id [get] func (this *OilSupplierCertAppendSubController) GetEntityThen() { InfoId := this.Ctx.Input.Param(":id") var model []suppliercertappendsub.OilAppendChangeItem svc := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE) where := " InfoId = " + InfoId svc.GetEntitysByWhere(OilAppendChangeItemName, where, &model) var datainfo DataInfo datainfo.Items = model this.Data["json"] = &datainfo this.ServeJSON() } // @Title 添加 // @Description 新增 // @Success 200 {object} controllers.Request // @router /addinfochangeitemch [post] func (this *OilSupplierCertAppendSubController) AddInfoChangeItemCh() { var model AppendChangeItemsAll var jsonBlob = this.Ctx.Input.RequestBody svc := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE) json.Unmarshal(jsonBlob, &model) var err error where := " SupplierId = " + model.SupplierId where = where + " and InfoId = " + model.MInfoId var deleteEntity suppliercertappendsub.OilAppendChangeItem delMainId, _ := strconv.Atoi(model.MInfoId) deleteEntity.InfoId = delMainId svc.DBE.Delete(deleteEntity) var infoitementitys []suppliercertappendsub.OilAppendChangeItem for i := 0; i < len(model.InfochangeForm); i++ { var infoitementity suppliercertappendsub.OilAppendChangeItem infoitementity.SelectItem = model.InfochangeForm[i].SelectItem infoitementity.SelectItemName = model.InfochangeForm[i].SelectItemName infoitementity.ChangeInfo = model.InfochangeForm[i].ChangeInfo infoitementity.BeChangeInfo = model.InfochangeForm[i].BeChangeInfo infoitementity.ChangeStatus = 0 infoitementity.SupplierId, _ = strconv.Atoi(model.SupplierId) infoitementity.InfoId, _ = strconv.Atoi(model.MInfoId) infoitementity.CreateOn = time.Now() infoitementity.CreateBy = this.User.Realname infoitementity.CreateUserId, _ = utils.StrTo(this.User.Id).Int() infoitementitys = append(infoitementitys, infoitementity) } _, err = svc.InsertEntityBytbl(""+OilAppendChangeItemName, &infoitementitys) var errinfo ErrorDataInfo if err == nil { //新增 errinfo.Message = "添加成功!" errinfo.Code = 0 //errinfo.Item = model.Id this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 资质文件 // @Description get user by token // @Success 200 {object} models.Userblood // @router /filelist [get] func (this *OilSupplierCertAppendSubController) FileList() { page := this.GetPageInfoForm() var list []suppliercertappendsub.OilAppendChangeDetail1 svc := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE) where := " 1=1" orderby := "a.SupplierTypeCode" asc := true Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = Prop if Order == "asc" { asc = true } } SupplierId := this.GetString("SupplierId") MInfoId := this.GetString("MInfoId") if SupplierId != "" { where = where + " and a.SupplierId = '" + SupplierId + "'" } SupplierTypeCode := this.GetString("SupplierTypeCode") if SupplierTypeCode != "" { where = where + " and a.SupplierTypeCode in ( '000', '" + SupplierTypeCode + "')" } total := svc.GetQualPagingEntities(OilSupplierFileName, OilAppendChangeDetailName, page.CurrentPage, page.Size, orderby, asc, &list, where, MInfoId) var datainfo DataInfo datainfo.Items = list datainfo.CurrentItemCount = total this.Data["json"] = &datainfo this.ServeJSON() } // @Title 资质文件变更上传 // @Description 更新文件上传 // @Param id path string true // @Success 200 {object} // @router /editqualchange/:id [put] func (this *OilSupplierCertAppendSubController) EditQualChange() { id := this.Ctx.Input.Param(":id") var errinfo ErrorInfo if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var model suppliercertappendsub.OilAppendChangeDetail var jsonblob = this.Ctx.Input.RequestBody svc := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE) json.Unmarshal(jsonblob, &model) model.FileUrl = strings.Trim(model.FileUrl, "$") model.FileName = strings.Trim(model.FileName, "$") model.OldFileUrl = strings.Trim(model.OldFileUrl, "$") model.OldFileName = strings.Trim(model.OldFileName, "$") var supplierfile supplierfile.OilSupplierFile svc.GetEntityByIdBytbl(OilSupplierFileName, model.Id, &supplierfile) if supplierfile.FileUrl == "" { //区别 更新前和更新后文件 supplierfile.FileUrl = strings.Trim(model.FileUrl, "$") supplierfile.FileName = strings.Trim(model.FileName, "$") supplierfile.EffectDate = model.EffectDate } supplierfile.ModifiedOn = time.Now() supplierfile.ModifiedUserId, _ = strconv.Atoi(this.User.Id) supplierfile.ModifiedBy = this.User.Realname supplierfile.OtherRemark = model.Remark svc.UpdateEntityBywheretbl(OilSupplierFileName, &supplierfile, []string{"EffectDate", "FileUrl", "FileName", "ModifiedOn", "ModifiedUserId", "ModifiedBy", "OtherRemark"}, "Id = " + strconv.Itoa(model.Id)) var err error var entity suppliercertappendsub.OilAppendChangeDetail var qualdetaimodel []suppliercertappendsub.OilAppendChangeDetail qdwhere := " SupplierId = " + utils.ToStr(model.SupplierId) + " and FileId = " + utils.ToStr(model.Id) + " and ParentId=" + id svc.GetEntitysByWhere(OilAppendChangeDetailName, qdwhere, &qualdetaimodel) entity = model entity.Id = 0 entity.ParentId, _ = strconv.Atoi(id) entity.SupplierCertId = model.SupplierCertId entity.FileId = model.Id if len(qualdetaimodel) == 0 { entity.CreateOn = time.Now() entity.CreateBy = this.User.Realname entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int() _, err = svc.InsertEntityBytbl(OilAppendChangeDetailName, &entity) } else { err = svc.UpdateEntityBywheretbl(OilAppendChangeDetailName, &entity, []string{"EffectDate", "FileUrl", "FileName", "OtherRemark"}, qdwhere) } if err == nil { errinfo.Message = "操作成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 删除新上传的资质 // @Description // @Success 200 {object} ErrorInfo // @Failure 403 :id 为空 // @router /deletenewfile/:Id [delete] func (this *OilSupplierCertAppendSubController) DeleteNewFile() { Id := this.Ctx.Input.Param(":Id") var errinfo ErrorInfo if Id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } svc := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE) where := "FileId=" + Id err := svc.DeleteEntityBytbl(OilAppendChangeDetailName, where) if err == nil { errinfo.Message = "删除成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } }