|
|
@@ -0,0 +1,313 @@
|
|
|
+package supplierlog
|
|
|
+
|
|
|
+import (
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/annualaudit"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/infochange"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/majorequip"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/manufacturer"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/patent"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/performance"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/qualchange"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/supplier"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/suppliercert"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/suppliercertappend"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/suppliercertappendsub"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/supplierfile"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/supplierscenefile"
|
|
|
+ "dashoo.cn/backend/api/business/oilsupplier/winning"
|
|
|
+ . "dashoo.cn/backend/api/mydb"
|
|
|
+ "dashoo.cn/utils"
|
|
|
+ "encoding/json"
|
|
|
+ "log"
|
|
|
+ "strconv"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ //"dashoo.cn/utils"
|
|
|
+ //. "dashoo.cn/utils/db"
|
|
|
+ "github.com/go-xorm/xorm"
|
|
|
+)
|
|
|
+
|
|
|
+type SupplierlogService struct {
|
|
|
+ MyServiceBase
|
|
|
+}
|
|
|
+
|
|
|
+func GetSupplierLogService(xormEngine *xorm.Engine) *SupplierlogService {
|
|
|
+ s := new(SupplierlogService)
|
|
|
+ s.DBE = xormEngine
|
|
|
+ return s
|
|
|
+}
|
|
|
+
|
|
|
+// 准入
|
|
|
+func (s *SupplierlogService) SaveSupplierLogForAccess(supplierId int, supplierCertId int) {
|
|
|
+ var model OilSupplierLog
|
|
|
+ s.GetEntityByWhere("OilSupplierLog", "SupplierId="+strconv.Itoa(supplierId)+" and SourceId= "+strconv.Itoa(supplierCertId)+" and OperType=1", &model)
|
|
|
+ if model.Id <= 0 {
|
|
|
+ // 准入申请信息--包含人员结构信息
|
|
|
+ certSrv := suppliercert.GetOilSupplierCertService(utils.DBE)
|
|
|
+ var supplierCertEntity suppliercert.OilSupplierCert
|
|
|
+ certSrv.GetEntityById(supplierCertId, &supplierCertEntity)
|
|
|
+
|
|
|
+ whereSupplierCert := "SupplierCertId=" + strconv.Itoa(supplierCertId)
|
|
|
+ whereSupplier := "SupplierId=" + strconv.Itoa(supplierCertEntity.SupplierId)
|
|
|
+ // 企业基本信息
|
|
|
+ supplierSrv := supplier.GetOilSupplierService(utils.DBE)
|
|
|
+ var supplierEntity supplier.OilSupplier
|
|
|
+ supplierSrv.GetEntityById(supplierCertEntity.SupplierId, &supplierEntity)
|
|
|
+ // 所代理制造商名称
|
|
|
+ manufSrv := manufacturer.GetmanufacturerService(utils.DBE)
|
|
|
+ var manufList []manufacturer.Manufacturer
|
|
|
+ manufSrv.GetEntitysByWhere("Manufacturer", whereSupplierCert, &manufList)
|
|
|
+ // 现场考察报告列表
|
|
|
+ sceneFileSrv := supplierscenefile.GetSupplierScenefileService(utils.DBE)
|
|
|
+ var sceneFileList []supplierscenefile.OilSupplierSceneFile
|
|
|
+ sceneFileSrv.GetEntitysByWhere("OilSupplierFile", whereSupplier, &sceneFileList)
|
|
|
+ // 主要设备
|
|
|
+ majorEquipmentSrv := majorequip.GetMajorequipService(utils.DBE)
|
|
|
+ var majorEquipmentList []majorequip.OilEnterpriseMajorEquipment
|
|
|
+ majorEquipmentSrv.GetEntitysByWhere("OilEnterpriseMajorEquipment", whereSupplierCert, &majorEquipmentList)
|
|
|
+ // 近三年主要业绩
|
|
|
+ threeYearsPerformanceSrv := performance.GetPerformanceService(utils.DBE)
|
|
|
+ var threeYearsPerformanceList []performance.OilThreeYearsPerformance
|
|
|
+ threeYearsPerformanceSrv.GetEntitysByWhere("OilThreeYearsPerformance", whereSupplierCert, &threeYearsPerformanceList)
|
|
|
+ // 专利及专有技术
|
|
|
+ patentTechSrv := patent.GetPatentService(utils.DBE)
|
|
|
+ var patentTechList []patent.OilPatentStatistical
|
|
|
+ patentTechSrv.GetEntitysByWhere("OilPatentStatistical", whereSupplierCert, &patentTechList)
|
|
|
+ // 近三年省部级及以上获奖项目
|
|
|
+ winningProSrv := winning.GetWinningService(utils.DBE)
|
|
|
+ var winingProList []winning.OilWinningProject
|
|
|
+ winningProSrv.GetEntitysByWhere("OilWinningProject", whereSupplierCert, &winingProList)
|
|
|
+ // 企业资质
|
|
|
+ certFileSrv := supplierfile.GetSupplierfileService(utils.DBE)
|
|
|
+ var certFileList []supplierfile.OilSupplierFile
|
|
|
+ certFileSrv.GetEntitysByWhere("OilSupplierFile", whereSupplier, &certFileList)
|
|
|
+ // 准入范围
|
|
|
+ certSubSrv := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
|
|
|
+ var certSubList []suppliercertsub.OilSupplierCertSub
|
|
|
+ certSubSrv.GetEntitysByWhere("OilSupplierCertSub", whereSupplier+" and Type=1 and "+whereSupplierCert+" and TypeCode="+supplierCertEntity.SupplierTypeCode, &certSubList)
|
|
|
+
|
|
|
+ // json 化数据
|
|
|
+ supplierBaseInfo, _ := json.Marshal(supplierEntity)
|
|
|
+ agencyManufacture, _ := json.Marshal(manufList)
|
|
|
+ inspectionReport, _ := json.Marshal(sceneFileList)
|
|
|
+ majorEquipment, _ := json.Marshal(majorEquipmentList)
|
|
|
+ threeYearsPerformance, _ := json.Marshal(threeYearsPerformanceList)
|
|
|
+ patentTech, _ := json.Marshal(patentTechList)
|
|
|
+ winingPro, _ := json.Marshal(winingProList)
|
|
|
+ certFile, _ := json.Marshal(certFileList)
|
|
|
+ certSub, _ := json.Marshal(certSubList)
|
|
|
+
|
|
|
+ // 插入日志信息
|
|
|
+ var model OilSupplierLog
|
|
|
+ model.SupplierId = supplierId
|
|
|
+ model.SourceID = supplierCertEntity.Id
|
|
|
+ model.NewSupplierName = supplierEntity.SupplierName
|
|
|
+ model.NewCommercialNo = supplierEntity.CommercialNo
|
|
|
+ model.OperType = 1
|
|
|
+ model.BaseInfo = string(supplierBaseInfo)
|
|
|
+ model.AgencyManufacture = string(agencyManufacture)
|
|
|
+ model.InspectionReport = string(inspectionReport)
|
|
|
+ model.Equipment = string(majorEquipment)
|
|
|
+ model.Performance = string(threeYearsPerformance)
|
|
|
+ model.Patent = string(patentTech)
|
|
|
+ model.AwardProject = string(winingPro)
|
|
|
+ model.CertFile = string(certFile)
|
|
|
+ model.CertSub = string(certSub)
|
|
|
+ model.CreateOn = time.Now()
|
|
|
+ _, err := s.InsertEntity(&model)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Println("不存在")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 增项
|
|
|
+func (s *SupplierlogService) SaveSupplierLogForAppend(supplierId int, supplierCertAppendId int) {
|
|
|
+ var model OilSupplierLog
|
|
|
+ s.GetEntityByWhere("OilSupplierLog", "SupplierId="+strconv.Itoa(supplierId)+" and SourceId= "+strconv.Itoa(supplierCertAppendId)+" and OperType=2", &model)
|
|
|
+ if model.Id <= 0 {
|
|
|
+ // 增项申请信息
|
|
|
+ appendCertSrv := suppliercertappend.GetOilSupplierCertAppendService(utils.DBE)
|
|
|
+ var appendCertEntity suppliercertappend.OilSupplierCertAppend
|
|
|
+ appendCertSrv.GetEntityById(supplierCertAppendId, &appendCertEntity)
|
|
|
+
|
|
|
+ whereSupplierCertAppend := " SupplierCertAppendId=" + strconv.Itoa(supplierCertAppendId)
|
|
|
+ whereSupplier := " SupplierId=" + strconv.Itoa(appendCertEntity.SupplierId)
|
|
|
+ // 原企业基本信息
|
|
|
+ //svc.GetEntityByIdBytbl(OilSupplierName, Id, &model)
|
|
|
+ supplierSrv := supplier.GetOilSupplierService(utils.DBE)
|
|
|
+ var supplierEntity supplier.OilSupplier
|
|
|
+ supplierSrv.GetEntityById(appendCertEntity.SupplierId, &supplierEntity)
|
|
|
+ // 企业基本信息 变更项
|
|
|
+ var changeInfoItems []suppliercertappendsub.OilAppendChangeItem
|
|
|
+ where := " SupplierId = " + strconv.Itoa(supplierId) + " and InfoId =" + strconv.Itoa(supplierCertAppendId)
|
|
|
+ where = where + " and ChangeStatus = 0"
|
|
|
+ supplierSrv.GetEntitysByWhere("OilAppendChangeItem", where, &changeInfoItems)
|
|
|
+
|
|
|
+ // 企业资质
|
|
|
+ var appendCertFileList []suppliercertappendsub.OilAppendChangeDetail
|
|
|
+ appendWhere := " a.SupplierId = " + strconv.Itoa(supplierId)
|
|
|
+ appendWhere = appendWhere + " and a.SupplierTypeCode in ( '000', '" + appendCertEntity.AppendType + "')"
|
|
|
+ appendCertSubSrv := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE)
|
|
|
+ appendCertSubSrv.GetQualPagingEntities("OilSupplierFile", "OilAppendChangeDetail", 1, 100, "a.Id", true, &appendCertFileList, appendWhere, strconv.Itoa(supplierCertAppendId))
|
|
|
+ // 准入范围 Type是3的就是本次新增的
|
|
|
+ certSubSrv := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
|
|
|
+ var certSubList []suppliercertsub.OilSupplierCertSub
|
|
|
+ certSubSrv.GetEntitysByWhere("OilSupplierCertSub", whereSupplier+" and "+whereSupplierCertAppend+" and Type IN ('1', '3') and SupplierTypeCode IN ('000', '"+appendCertEntity.AppendType+"')", &certSubList)
|
|
|
+ // json 化数据 SupplierTypeCode
|
|
|
+ supplierBaseInfo, _ := json.Marshal(supplierEntity)
|
|
|
+ supplierBaseInfoChangeItem, _ := json.Marshal(changeInfoItems)
|
|
|
+ certFile, _ := json.Marshal(appendCertFileList)
|
|
|
+ certSub, _ := json.Marshal(certSubList)
|
|
|
+
|
|
|
+ // 插入日志信息
|
|
|
+ var model OilSupplierLog
|
|
|
+ model.SupplierId = supplierId
|
|
|
+ model.SourceID = supplierCertAppendId
|
|
|
+ model.NewSupplierName = supplierEntity.SupplierName
|
|
|
+ model.NewCommercialNo = supplierEntity.CommercialNo
|
|
|
+ model.OperType = 2
|
|
|
+ model.BaseInfo = string(supplierBaseInfo) + "&& " + string(supplierBaseInfoChangeItem)
|
|
|
+ model.CertFile = string(certFile)
|
|
|
+ model.CertSub = string(certSub)
|
|
|
+ model.CreateOn = time.Now()
|
|
|
+ _, err := s.InsertEntity(&model)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Println("已存在")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 年审
|
|
|
+func (s *SupplierlogService) SaveSupplierLogForAnnual(supplierId int, annualId int) {
|
|
|
+ var model OilSupplierLog
|
|
|
+ s.GetEntityByWhere("OilSupplierLog", "SupplierId="+strconv.Itoa(supplierId)+" and SourceId= "+strconv.Itoa(annualId)+" and OperType=3", &model)
|
|
|
+ if model.Id <= 0 {
|
|
|
+ // 年审申请信息
|
|
|
+ annualSrv := annualaudit.GetOilAnnualAuditService(utils.DBE)
|
|
|
+ var annualEntity annualaudit.OilAnnualAudit
|
|
|
+ annualSrv.GetEntityById(annualId, &annualEntity)
|
|
|
+
|
|
|
+ // 原企业基本信息
|
|
|
+ //svc.GetEntityByIdBytbl(OilSupplierName, Id, &model)
|
|
|
+ supplierSrv := supplier.GetOilSupplierService(utils.DBE)
|
|
|
+ var supplierEntity supplier.OilSupplier
|
|
|
+ supplierSrv.GetEntityById(annualEntity.SupplierId, &supplierEntity)
|
|
|
+ // 企业基本信息 变更项
|
|
|
+ var changeInfoItems []infochange.OilAnnualChangeItem
|
|
|
+ whereAnnual := " InfoId = " + strconv.Itoa(annualId)
|
|
|
+ supplierSrv.GetEntitysByWhere("OilAnnualChangeItem", whereAnnual, &changeInfoItems)
|
|
|
+
|
|
|
+ // 企业资质
|
|
|
+ var annualCertFileList []qualchange.OilQualChangeDetail
|
|
|
+ annualWhere := " a.SupplierId = " + strconv.Itoa(supplierId)
|
|
|
+ annualWhere = annualWhere + " and a.SupplierTypeCode in ( '000', '" + annualEntity.SupplierTypeName + "')"
|
|
|
+ annualCertSubSrv := suppliercertappendsub.GetOilSupplierCertAppendSubService(utils.DBE)
|
|
|
+ annualCertSubSrv.GetQualPagingEntities("OilSupplierFile", "OilAnnualChangeDetail", 1, 100, "a.Id", true, &annualCertFileList, annualWhere, strconv.Itoa(annualId))
|
|
|
+
|
|
|
+ whereSupplierCert := "SupplierCertId=" + strconv.Itoa(annualEntity.CerId)
|
|
|
+ // 主要设备
|
|
|
+ majorEquipmentSrv := majorequip.GetMajorequipService(utils.DBE)
|
|
|
+ var majorEquipmentList []majorequip.OilEnterpriseMajorEquipment
|
|
|
+ majorEquipmentSrv.GetEntitysByWhere("OilEnterpriseMajorEquipment", whereSupplierCert, &majorEquipmentList)
|
|
|
+ // 近三年主要业绩
|
|
|
+ threeYearsPerformanceSrv := performance.GetPerformanceService(utils.DBE)
|
|
|
+ var threeYearsPerformanceList []performance.OilThreeYearsPerformance
|
|
|
+ threeYearsPerformanceSrv.GetEntitysByWhere("OilThreeYearsPerformance", whereSupplierCert, &threeYearsPerformanceList)
|
|
|
+ // 专利及专有技术
|
|
|
+ patentTechSrv := patent.GetPatentService(utils.DBE)
|
|
|
+ var patentTechList []patent.OilPatentStatistical
|
|
|
+ patentTechSrv.GetEntitysByWhere("OilPatentStatistical", whereSupplierCert, &patentTechList)
|
|
|
+ // 近三年省部级及以上获奖项目
|
|
|
+ winningProSrv := winning.GetWinningService(utils.DBE)
|
|
|
+ var winingProList []winning.OilWinningProject
|
|
|
+ winningProSrv.GetEntitysByWhere("OilWinningProject", whereSupplierCert, &winingProList)
|
|
|
+
|
|
|
+ // json 化数据
|
|
|
+ supplierBaseInfo, _ := json.Marshal(supplierEntity)
|
|
|
+ supplierBaseInfoChangeItem, _ := json.Marshal(changeInfoItems)
|
|
|
+ majorEquipment, _ := json.Marshal(majorEquipmentList)
|
|
|
+ threeYearsPerformance, _ := json.Marshal(threeYearsPerformanceList)
|
|
|
+ patentTech, _ := json.Marshal(patentTechList)
|
|
|
+ winingPro, _ := json.Marshal(winingProList)
|
|
|
+ certFile, _ := json.Marshal(annualCertFileList)
|
|
|
+
|
|
|
+ // 插入日志信息
|
|
|
+ var model OilSupplierLog
|
|
|
+ model.SupplierId = supplierId
|
|
|
+ model.SourceID = annualId
|
|
|
+ model.NewSupplierName = supplierEntity.SupplierName
|
|
|
+ model.NewCommercialNo = supplierEntity.CommercialNo
|
|
|
+ model.OperType = 3 // 年审
|
|
|
+ model.BaseInfo = string(supplierBaseInfo) + "&" + string(supplierBaseInfoChangeItem)
|
|
|
+ model.Equipment = string(majorEquipment)
|
|
|
+ model.Performance = string(threeYearsPerformance)
|
|
|
+ model.Patent = string(patentTech)
|
|
|
+ model.AwardProject = string(winingPro)
|
|
|
+ model.CertFile = string(certFile)
|
|
|
+ model.CreateOn = time.Now()
|
|
|
+ _, err := s.InsertEntity(&model)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Println("已存在")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 信息变更
|
|
|
+func (s *SupplierlogService) SaveSupplierLogForInfoChange(supplierId int, infoChangeId int) {
|
|
|
+ var model OilSupplierLog
|
|
|
+ s.GetEntityByWhere("OilSupplierLog", "SupplierId="+strconv.Itoa(supplierId)+" and SourceId= "+strconv.Itoa(infoChangeId)+" and OperType=4", &model)
|
|
|
+ if model.Id <= 0 {
|
|
|
+ // 信息变更申请信息
|
|
|
+ changeSrv := infochange.GetInfoChangeService(utils.DBE)
|
|
|
+ var infoChangeEntity infochange.OilInfoChange
|
|
|
+ changeSrv.GetEntityById(infoChangeId, &infoChangeEntity)
|
|
|
+
|
|
|
+ // 原企业基本信息
|
|
|
+ //svc.GetEntityByIdBytbl(OilSupplierName, Id, &model)
|
|
|
+ supplierSrv := supplier.GetOilSupplierService(utils.DBE)
|
|
|
+ var supplierEntity supplier.OilSupplier
|
|
|
+ supplierSrv.GetEntityById(infoChangeEntity.SupplierId, &supplierEntity)
|
|
|
+ // 企业基本信息 变更项
|
|
|
+ var changeInfoItems []infochange.OilInfoChangeItem
|
|
|
+ svc := infochange.GetInfoChangeService(utils.DBE)
|
|
|
+ where := " InfoId = " + strconv.Itoa(infoChangeId)
|
|
|
+ svc.GetEntitysByWhere("OilInfoChangeItem", where, &changeInfoItems)
|
|
|
+
|
|
|
+ // 企业资质
|
|
|
+ var allCertFileList []qualchange.OilQualChangeDetail
|
|
|
+ changeWhere := " a.SupplierId = " + strconv.Itoa(supplierId)
|
|
|
+ //changeWhere = changeWhere + " and a.SupplierTypeCode in ( '000', '" + infoChangeEntity.SupplierTypeCode + "')" // 取全部资质 不再筛选
|
|
|
+ allCertSubSrv := qualchange.GetQualChangeService(utils.DBE)
|
|
|
+ allCertSubSrv.GetQualPagingEntities("OilSupplierFile", "OilQualChangeDetail", 1, 1000, "a.Id", true, &allCertFileList, changeWhere, strconv.Itoa(infoChangeId))
|
|
|
+
|
|
|
+ // json 化数据
|
|
|
+ supplierBaseInfo, _ := json.Marshal(supplierEntity)
|
|
|
+ supplierBaseInfoChangeItem, _ := json.Marshal(changeInfoItems)
|
|
|
+ certFile, _ := json.Marshal(allCertFileList)
|
|
|
+
|
|
|
+ // 插入日志信息
|
|
|
+ var model OilSupplierLog
|
|
|
+ model.SupplierId = supplierId
|
|
|
+ model.SourceID = infoChangeId
|
|
|
+ model.NewSupplierName = supplierEntity.SupplierName
|
|
|
+ model.NewCommercialNo = supplierEntity.CommercialNo
|
|
|
+ model.OperType = 4
|
|
|
+ model.BaseInfo = string(supplierBaseInfo) + "&" + string(supplierBaseInfoChangeItem)
|
|
|
+ model.CertFile = string(certFile)
|
|
|
+ model.CreateOn = time.Now()
|
|
|
+ _, err := s.InsertEntity(&model)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Println("已存在")
|
|
|
+ }
|
|
|
+}
|