#!/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


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

    def industryOne(self):
        return self.dataBase.sqlResult(
            'SELECT industry_one,industry_one_code FROM ent_qualification GROUP BY industry_one ORDER BY id')

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

    def selectQualifications(self, export_label, store_type_code, industry_one_code, industry_two_code):
        if industry_one_code in ('25', '28', '36', '37') or industry_two_code in (
        '2716', '3041', '3042', '3043', '3044', '3045', '3258', '3476'):
            return self.dataBase.sqlResult(
                "SELECT * FROM `ent_qualification` WHERE store_type_code = '%s' and industry_one_code = '%s' and industry_two_code = '%s'" % (
                store_type_code, industry_one_code, industry_two_code))
        else:
            print("SELECT * FROM `ent_qualification` WHERE export_label = '%s' AND store_type_code = '%s' and industry_one_code = '%s' and industry_two_code = '%s'" % (
                    export_label, store_type_code, industry_one_code, industry_two_code))
            return self.dataBase.sqlResult(
                "SELECT * FROM `ent_qualification` WHERE export_label = '%s' AND store_type_code = '%s' and industry_one_code = '%s' and industry_two_code = '%s'" % (
                    export_label, store_type_code, industry_one_code, industry_two_code))
