#!/usr/bin/env python
# -*- coding:utf-8 -*- 
# Author: hj
# softWare:pycharm
# fileName:ent_qualification.py
# createTime:2020/7/19 13:15

from db.mod_db import Database
from common.sql_utils import to_sql_in



class qualificationsDao:
    def __init__(self, db=None):
        if db is None:
            self.dataBase = Database()
        else:
            self.dataBase = db

    def industryOne(self,platform_code):
        return self.dataBase.sqlResult(
            'SELECT industry_one,industry_one_code FROM ent_qualification where platform_code = "%s" GROUP BY industry_one ORDER BY id'% platform_code)

    def industryTwo(self, industry_one_code,platform_code):
        return self.dataBase.sqlResult(
            'SELECT industry_two_code,industry_two FROM ent_qualification  WHERE industry_one_code = "%s" and platform_code = "%s" GROUP BY industry_two ORDER BY id' % (industry_one_code,platform_code))

    def selectQualifications(self,platform_code,export_label, store_type_code, industry_one_code, industry_two_code_list):
        return self.dataBase.sqlResult(
            "SELECT * FROM `ent_qualification` WHERE platform_code = '%s' and export_label in %s AND store_type_code = '%s' and industry_one_code = '%s' and industry_two_code in (%s) AND enter_label != '0'" % (
                platform_code,export_label, store_type_code, industry_one_code, to_sql_in(industry_two_code_list)))

    def selectQualificationsUse(self, platform_code,export_label, store_type_code, industry_one_code, industry_two_code):
        print( "SELECT * FROM `ent_qualification` WHERE export_label in %s AND store_type_code = '%s' and industry_one_code = '%s' and platform_code = '%s' and industry_two_code in (%s) and industry_label = 1" % (
                export_label, store_type_code, industry_one_code,platform_code, to_sql_in(industry_two_code)))
        return self.dataBase.sqlResult(
            "SELECT * FROM `ent_qualification` WHERE export_label in %s AND store_type_code = '%s' and industry_one_code = '%s' and platform_code = '%s' and industry_two_code in (%s) and industry_label = 1" % (
                export_label, store_type_code, industry_one_code,platform_code, to_sql_in(industry_two_code)))

