| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- package supplier
- import (
- . "dashoo.cn/backend/api/mydb"
- "dashoo.cn/utils"
- "github.com/go-xorm/xorm"
- "strconv"
- )
- type OilSupplierService struct {
- MyServiceBase
- }
- func GetOilSupplierService(xormEngine *xorm.Engine) *OilSupplierService {
- s := new(OilSupplierService)
- s.DBE = xormEngine
- return s
- }
- //
- func (s *OilSupplierService) GetMyPagingEntitiesWithOrderBytbl(supplierTableName, supplierCertTableName string, pageIndex, itemsPerPage int64, orderby string, asc bool, entitiesPtr interface{}, where string) (total int64) {
- var resultsSlice []map[string][]byte
- //获取总记录数
- sqlCount := `select count(*) from ` + supplierTableName + ` a `
- sqlCount += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
- sqlCount += ` where ` + where
- var sql string
- sql = `select a.*, b.Id as CertId, b.AccessCardNo, b.SupplierTypeCode, b.SupplierTypeName, b.InFlag, b.ApplyTime, `
- sql += ` b.WorkerTotal, `
- sql += ` b.ContractNum, `
- sql += ` b.UniversityNum, `
- sql += ` b.TechnicalNum, `
- sql += ` b.AboveProfNum, `
- sql += ` b.MiddleProfNum, `
- sql += ` b.NationalRegNum, `
- sql += ` b.NationalCertTotal, `
- sql += ` b.DesignerTotal, `
- sql += ` b.SkillerTotal, `
- sql += ` b.Status, `
- sql += ` b.WorkflowId, b.CreateOn ,b.ProcessKey,b.BusinessKey`
- sql += ` from ` + supplierTableName + ` a `
- sql += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
- sql += ` where ` + where
- if asc {
- sql += ` order by ` + orderby + ` ASC `
- } else {
- sql += ` order by ` + orderby + ` DESC `
- }
- if (pageIndex != 0 && itemsPerPage !=0) {
- sql += ` limit ` + utils.ToStr((pageIndex-1)*itemsPerPage) + "," + utils.ToStr(itemsPerPage)
- }
- s.DBE.SQL(sql).Find(entitiesPtr)
- resultsSlice, _ = s.DBE.Query(sqlCount)
- if len(resultsSlice) > 0 {
- results := resultsSlice[0]
- for _, value := range results {
- total, _ = strconv.ParseInt(string(value), 10, 64)
- break
- }
- }
- return total
- }
- func (s *OilSupplierService) CheckRepeatApplyInfo(supplierTableName, supplierCertTableName, typeCode, SupplierName, CommercialNo, OrganCode, BankAccount, CompanyUrl string, entitiesPtr interface{}) {
- //获取分页信息
- where2 := " b.SupplierTypeCode = '" + typeCode + "'"
- where := ""
- if SupplierName != "" {
- where = where + " or a.SupplierName = '" + SupplierName + "'"
- }
- if CommercialNo != "" {
- where = where + " or a.CommercialNo = '" + CommercialNo + "'"
- }
- if OrganCode != "" {
- where = where + " or a.OrganCode = '" + OrganCode + "'"
- }
- if BankAccount != "" {
- where = where + " or a.BankAccount = '" + BankAccount + "'"
- }
- if CompanyUrl != "" {
- where = where + " or a.CompanyUrl = '" + CompanyUrl + "'"
- }
- if len(where) > 0 {
- where2 += " and (1=0 " + where + ")"
- var sql string
- sql = `select a.*, b.Id as CertId, b.AccessCardNo, b.SupplierTypeCode, b.SupplierTypeName, `
- sql += ` b.WorkerTotal, `
- sql += ` b.ContractNum, `
- sql += ` b.UniversityNum, `
- sql += ` b.TechnicalNum, `
- sql += ` b.AboveProfNum, `
- sql += ` b.MiddleProfNum, `
- sql += ` b.NationalRegNum, `
- sql += ` b.NationalCertTotal, `
- sql += ` b.DesignerTotal, `
- sql += ` b.SkillerTotal, `
- sql += ` b.Status, `
- sql += ` b.WorkflowId `
- sql += ` from ` + supplierTableName + ` a `
- sql += ` right join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
- sql += ` where ` + where2
- s.DBE.SQL(sql).Find(entitiesPtr)
- }
- }
- func (s *OilSupplierService) CheckUpdateRepeatApplyInfo(supplierTableName, supplierCertTableName, typeCode, supplierId, SupplierName, CommercialNo, OrganCode, BankAccount, CompanyUrl string, entitiesPtr interface{}) {
- //获取分页信息
- where2 := " a.Id != '" + supplierId + "'"
- where := ""
- if SupplierName != "" {
- where = where + " or a.SupplierName = '" + SupplierName + "'"
- }
- if CommercialNo != "" {
- where = where + " or a.CommercialNo = '" + CommercialNo + "'"
- }
- if OrganCode != "" {
- where = where + " or a.OrganCode = '" + OrganCode + "'"
- }
- if BankAccount != "" {
- where = where + " or a.BankAccount = '" + BankAccount + "'"
- }
- if CompanyUrl != "" {
- where = where + " or a.CompanyUrl = '" + CompanyUrl + "'"
- }
- if len(where) > 0 {
- where2 += " and (1=0 " + where + ")"
- var sql string
- sql = `select a.*, b.Id as CertId, b.AccessCardNo, b.SupplierTypeCode, b.SupplierTypeName, `
- sql += ` b.WorkerTotal, `
- sql += ` b.ContractNum, `
- sql += ` b.UniversityNum, `
- sql += ` b.TechnicalNum, `
- sql += ` b.AboveProfNum, `
- sql += ` b.MiddleProfNum, `
- sql += ` b.NationalRegNum, `
- sql += ` b.NationalCertTotal, `
- sql += ` b.DesignerTotal, `
- sql += ` b.SkillerTotal, `
- sql += ` b.Status, `
- sql += ` b.WorkflowId `
- sql += ` from ` + supplierTableName + ` a `
- sql += ` right join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
- sql += ` where ` + where2
- s.DBE.SQL(sql).Find(entitiesPtr)
- }
- }
- func (s *OilSupplierService) CanUpdateSupplier(oilSupplierCertTableName string, supplierId int) (bool){
- session := s.DBE.NewSession()
- sessionSvc := GetOilSupplierSession(session)
- defer session.Close()
- session.Begin()
- result := sessionSvc.CanUpdateSupplier(oilSupplierCertTableName, supplierId)
- session.Commit()
- return result
- }
- func (s *OilSupplierService) GetUpdateCols(oilSupplierCertTableName string, supplierTypeCode string, supplierId int) ([]string){
- session := s.DBE.NewSession()
- sessionSvc := GetOilSupplierSession(session)
- defer session.Close()
- session.Begin()
- cols := sessionSvc.GetUpdateCols(oilSupplierCertTableName, supplierTypeCode, supplierId)
- session.Commit()
- return cols
- }
- func (s *OilSupplierService) GetProOrTreeList(ids string, entitiesPtr interface{}){
- where := " Id in ("+ids+")"
- sql := "SELECT Id, FullName, ParentId FROM Base_Organize where " + where
- s.DBE.SQL(sql).Find(entitiesPtr)
- return
- }
- func (s *OilSupplierService) GetMyTodoEntitie(supplierTableName, supplierCertTableName string, entitiesPtr interface{}, where string) bool {
- var sql string
- sql = `select a.Id, a.SupplierName, b.Id as CertId, b.SupplierTypeCode, '1' Type, b.Status `
- sql += ` from ` + supplierTableName + ` a `
- sql += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
- sql += ` where ` + where
- has,_ := s.DBE.SQL(sql).Get(entitiesPtr)
- return has
- }
- func (s *OilSupplierService) GetExpireFile(supplierTableName, supplierFileTableName string, entitiesPtr interface{}, where string) error {
- var sql string
- sql = `SELECT a.Id, a.SupplierName, a.Mobile, a.CreateBy, a.ContactName, a.CreateUserId, GROUP_CONCAT(b.NeedFileType SEPARATOR ';' ) NeedAllFile `
- sql += ` FROM ` + supplierTableName + ` a `
- sql += ` left join ` + supplierFileTableName + " b ON a.Id=b.SupplierId "
- sql += ` where ` + where
- sql += ` GROUP BY a.Id, a.SupplierName, a.Mobile `
- err := s.DBE.SQL(sql).Find(entitiesPtr)
- return err
- }
- func (s *OilSupplierService) GetInterfaceData(supplierTableName, supplierFileTableName string, entitiesPtr interface{}, where string) error {
- var sql string
- sql = `SELECT a.Id, a.SupplierName, a.RegCapital, GROUP_CONCAT(b.NeedFileType SEPARATOR ';' ) NeedAllFile `
- sql += ` FROM ` + supplierTableName + ` a `
- sql += ` left join ` + supplierFileTableName + " b ON a.Id=b.SupplierId "
- sql += ` where ` + where
- sql += ` GROUP BY a.Id, a.SupplierName, a.Mobile `
- err := s.DBE.SQL(sql).Find(entitiesPtr)
- return err
- }
- func (s *OilSupplierService) GetProcessInfoWithOrderBytbl(supplierTableName, supplierCertTableName string, pageIndex, itemsPerPage int64, orderby string, asc bool, entitiesPtr interface{}, where string) (total int64) {
- var resultsSlice []map[string][]byte
- //获取总记录数
- sqlCount := `select count(*) from ` + supplierCertTableName + ` a `
- sqlCount += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
- sqlCount += ` where ` + where
- var sql string
- sql = `select a.SupplierName, b.Id, `
- sql += ` b.Status, b.SupplierTypeCode, `
- sql += ` b.WorkflowId, b.ProcessKey, '1' as Type, b.CreateOn`
- sql += ` from ` + supplierTableName + ` a `
- sql += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
- sql += ` where ` + where
- if asc {
- sql += ` order by ` + orderby + ` ASC `
- } else {
- sql += ` order by ` + orderby + ` DESC `
- }
- if (pageIndex != 0 && itemsPerPage !=0) {
- sql += ` limit ` + utils.ToStr((pageIndex-1)*itemsPerPage) + "," + utils.ToStr(itemsPerPage)
- }
- s.DBE.SQL(sql).Find(entitiesPtr)
- resultsSlice, _ = s.DBE.Query(sqlCount)
- if len(resultsSlice) > 0 {
- results := resultsSlice[0]
- for _, value := range results {
- total, _ = strconv.ParseInt(string(value), 10, 64)
- break
- }
- }
- return total
- }
|