首页 > 数据库 >more Layer Architecture in Python and postgreSQL17.0

more Layer Architecture in Python and postgreSQL17.0

时间:2024-11-13 20:00:05浏览次数:1  
标签:info Layer SchoolId return Python postgreSQL17.0 self def cls

postgreSQL script:

create table School  -- 創建表
(
    SchoolId char(5) NOT NULL PRIMARY KEY,   
    SchoolName varchar(500) NOT NULL DEFAULT '', 
    SchoolTelNo  varchar(8)  NULL DEFAULT '' 
);

  

model:

# encoding: utf-8
# 版权所有 2024 ©涂聚文有限公司
# 许可信息查看:言語成了邀功的功臣,還需要行爲每日來值班嗎?
# 描述:
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 3.11
# OS        : windows 10
# Datetime  : 2024/10/12 21:53
# User      : geovindu
# Product   : PyCharm
# Project   : IctGame
# File      : model/school.py
# explain   : 学习
 
class SchoolInfo(object):
    """
    學校實體對象
    https://docs.python.org/3/library/functions.html
    https://docs.python.org/3/howto/descriptor.html
    """
 
    def __init__(self):
        """
        構造
        """
        self._SchoolId = None
        """
        primary key
        """
        self._SchoolName = None
        """
        學校名稱
        """
        self._SchoolTelNo = None
        """
        學校電號碼
        """
 
    @property
    def SchoolId(self):
        """
        primary key
        """
        return self._SchoolId
 
    @SchoolId.setter
    def SchoolId(self, schoolId):
        """
        primary key
        :param SchoolId:
        :return:
        """
        self._SchoolId = schoolId
 
    @property
    def SchoolName(self):
        """
        學校名稱
        """
        return self._SchoolName
 
    @SchoolName.setter
    def SchoolName(self, schoolName):
        """
        學校名稱
        :param SchoolName:
        :return:
        """
        self._SchoolName = schoolName
 
    @property
    def SchoolTelNo(self):
        """
        學校電話
        """
        return self._SchoolTelNo
 
    @SchoolTelNo.setter
    def SchoolTelNo(self, schoolTelNo):
        """
        學校電話 賦值
        :param SchoolTelNo:
        :return:
        """
        self._SchoolTelNo = schoolTelNo
 
    '''
    def ToString(self):
        """
        顯示一行實體對象
        :return:
        """
        return "{0}\t{1}\t{2}".format(self._SchoolId, self._SchoolName, self._SchoolTelNo)
    def __del__(self):
        print('{}对象已经被销毁'.format(self.__name__))
    '''
# test

  IDAL:

 

# encoding: utf-8
# 版权所有 2024 ©涂聚文有限公司
# 许可信息查看:言語成了邀功的功臣,還需要行爲每日來值班嗎?
# 描述:
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 3.11
# OS        : windows 10
# Datetime  : 2024/11/13  22:22
# User      : geovindu
# Product   : PyCharm
# Project   : IctGame
# File      : school.py
# explain   : 学习
 
from __future__ import annotations
from abc import ABC, abstractmethod
import os
import sys
from model.school import SchoolInfo
 
 
class ISchool(ABC):
    """
    """
 
 
    @classmethod
    def __subclasshook__(cls, subclass):
        return (hasattr(subclass, 'load_data_source') and
                callable(subclass.load_data_source) and
                hasattr(subclass, 'extract_text') and
                callable(subclass.extract_text) or
                NotImplemented)
 
    @abstractmethod
    def selectSql(cls):
        """
        :return:
        """
        pass
 
    @abstractmethod
    def selectSqlCount(cls) -> list:
        """
        查询数据 总数
        :return:
        """
        pass
 
    @abstractmethod
    def selectSqlOrder(cls, order: str) -> list:
        """
        :param order:
        :return:
        """
        pass
 
    @abstractmethod
    def selectSort(cls,field:str,isOrder:bool)->list:
        """
        :param field SchoolId
        :param order:  desc/asc
        :return:
        """
        pass
 
    @abstractmethod
    def selectIdSql(cls, SchoolId: str):
        """
        :param StudentId:
        :return:
        """
        pass
 
    @abstractmethod
    def selectProc(cls):
        """
        :return:
        """
        pass
 
    @abstractmethod
    def selectIdProc(cls, SchoolId: str):
        """
        :param SchoolId:
        :return:
        """
        pass
 
    @abstractmethod
    def addSql(cls, info: SchoolInfo):
        """
        :param info:
        :return:
        """
        pass
 
    @abstractmethod
    def addProc(cls, info: SchoolInfo):
        """
        :param info:
        :return:
        """
        pass
 
    @abstractmethod
    def addOutProc(cls, info: SchoolInfo):
        """
        :param info:
        :return:
        """
        pass
 
    @abstractmethod
    def editSql(cls, info: SchoolInfo):
        """
        :param info:
        :return:
        """
        pass
 
    @abstractmethod
    def editProc(cls, info: SchoolInfo):
        """
        :param info:
        :return:
        """
        pass
 
    @abstractmethod
    def delSql(cls, SchoolId: str):
        """
        :param SchoolId:
        :return:
        """
        pass
 
    @abstractmethod
    def delProc(cls, SchoolId:str):
        """
        :param SchoolId:
        :return:
        """
        pass

  

DAL:

# encoding: utf-8
# 版权所有 2024 ©涂聚文有限公司
# 许可信息查看:言語成了邀功的功臣,還需要行爲每日來值班嗎?
# 描述:
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 3.11
# OS        : windows 10
# Datetime  : 2024/11/13  22:22
# User      : geovindu
# Product   : PyCharm
# Project   : IctGame
# File      : school.py
# explain   : 学习
 
import os
import sys
from pathlib import Path
import re
import pymssql  #sql server
from model.school import SchoolInfo
from DBUtility.postgreSQLHelper import PostgreSqlHelper
from postgresqlinterface.school import ISchool
 
class SchoolDal(ISchool):
    """
    """
    myms = PostgreSqlHelper()
 
    def __init__(self):
        """
        构造函数,方法
        :param strserver:
        :param struser:
        :param strpwd:
        :param strdatabase:
        """
        self._strserver = ""
        self._struser = ""
        self._strpwd = ""
        self._strdatabase =""
 
    def selectSql(cls)->list:
        """
        查询数据 self._strserver, self._struser, self._strpwd, self._strdatabase
        :return:
        """
 
 
        row=cls.myms.execute("select * from School;")
        #cls.myms.close()
        return row
 
    def selectSqlCount(cls)->list:
        """
        查询数据 总数
        :return:
        """
 
        row=cls.myms.execute("select count(*) as total from School;")
        #cls.myms.close()
        return row[0]
 
 
    def selectSqlOrder(cls,order:str)->list:
        """
        :param order:  SchoolId desc/asc
        :return:
        """
        students=[]
 
        strsql=f"select * from School order by {order};"
        row=cls.myms.execute(f"select * from School order by {order};")
        return row
 
    def selectSort(cls,field:str,isOrder:bool)->list:
        """
        :param field SchoolId
        :param order:  desc/asc
        :return:
        """
        order='desc'
        if isOrder==True:
            order='desc'
        else:
            order='asc'
        strsql=f"select * from School order by {field} {order};"
        row=cls.myms.execute(f"select * from School order by {field} {order};")
        #cls.myms.close()
        return row
 
 
    def selectIdSql(cls,SchoolId:str)->list:
        """
        :param StudentId: 主键ID
        :return:
        """
 
        row=cls.myms.execute(f"select * from School where SchoolId='{SchoolId}';")
        #cls.myms.close()
        return row
 
    def selectProc(cls)->list:
        """
        存储过程
        :return:
        """
 
        args = ()
        row = cls.myms.executeCallProc("procSelectSchoolAll",args)
        return row
 
    def selectIdProc(cls,SchoolId:str)->list:
        """
        存储过程
        :param SchoolId: 主键ID
        :return:
        """
 
        args = (SchoolId,)
        row = cls.myms.executeCallProc('procSelectSchool', args)
        return row
 
    def addSql(cls,info:SchoolInfo)->int:
        """
        添加,要考虑添加返回ID值
        :param info:实体类
        :return:
        """
 
        column=("SchoolId","SchoolName","SchoolTelNo")
        vales=[info.SchoolId,info.SchoolName,info.SchoolTelNo]
        return cls.myms.insertByColumnaAndValues("School",column,vales)
 
    def addProc(cls,info:SchoolInfo)->int:
        """
        添加,要考虑添加返回ID值
        :param info:实体类
        :return:
        """
 
        args=[info.SchoolId,info.SchoolName,info.SchoolTelNo]
        return cls.myms.insertCallProc("procInsertSchool",args)
 
    def addOutProc(cls,info:SchoolInfo) -> int:
        """
        添加,要考虑添加返回ID值
        :param info:实体类
        :return: 返回增加的ID
        """
        id = 0
        try:
 
            outid =('int',) #输出,元组类型
            print(info)
            args = [info.SchoolName, info.SchoolTelNo,outid]
            print(args)
            result=cls.myms.insertOutCallProc("procInsertSchoolOutput", args)
            print(result)
            id = result
        except Exception as ex:
            print(ex)
        return id
 
    def editSql(cls,info:SchoolInfo)->int:
        """
        :param info:实体类
        :return:
        """
 
        args = {"SchoolId":f"{info.SchoolId}","SchoolName":f"{info.SchoolName()}","SchoolTelNo":f"{info.SchoolTelNo}"}  #"StudentId":6
        where = f"SchoolId={info.SchoolId}" #
        #print(args,where)
        return cls.myms.updateByKeyValues("School",where,args)
 
    def editProc(cls, info: SchoolInfo)->int:
        """
        :param info: 实体类
        :return:
        """
 
        args = [info.SchoolId,info.SchoolName,info.SchoolTelNo]
        return cls.myms.updateProc("procUpdateSchool",args)
 
 
    def delSql(cls,SchoolId:str)->int:
        """
        sql语句删除
        :param SchoolId: 主键ID
        :return:
        """
 
        where={f"SchoolId":SchoolId}
        return cls.myms.deleteByKeyValues("School",where)
 
    def delProc(cls, SchoolId:str)->int:
        """
        删除 存储过程 删除多个ID,后面增加
        :param SchoolId: 主键ID
        :return:
        """
 
        args =SchoolId
        k=cls.myms.deleteProc("procDuDeleteSchool", args)
 
        return k
 

  

BLL:

# encoding: utf-8
# 版权所有 2024 ©涂聚文有限公司
# 许可信息查看:言語成了邀功的功臣,還需要行爲每日來值班嗎?
# 描述:
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 3.11
# OS        : windows 10
# Datetime  : 2024/11/13  22:22
# User      : geovindu
# Product   : PyCharm
# Project   : IctGame
# File      : school.py
# explain   : 学习
 
import os
import sys
from pathlib import Path
import re
import pymssql  #sql server
from datetime import date
from model.school import SchoolInfo
from field.school import SchoolField
from postgresqlfactory.AbstractFactory import AbstractFactory
 
 
class SchoolBll(object):
    """
    学生信息操作业务类
    """
 
    dal=AbstractFactory.createSchool
    """
    类属性 接口DAL
    """
    def __init__(self):
        """
        """
        self.__name = "SchoolBll"
        self._field = SchoolField()
 
    def __del__(self):
        print(f"{self.__name} ERASE MEMORY")
 
 
    def select(self) -> list[SchoolInfo]:
        """
        :return:
        """
 
        students = []
 
        data = self.dal().selectSql()
        if len(data) > 0:
            for SchoolId, SchoolName, SchoolTelNo in data[0]:
                info = SchoolInfo()
                info.SchoolId = SchoolId
                info.SchoolName = SchoolName
                info.SchoolTelNo = SchoolTelNo
                students.append(info)
        return students
 
    def selectSql(cls) -> list[SchoolInfo]:
        """
        元组数据
        :return: list 列表
        """
        students = []
 
        data = cls.dal().selectSql()
        if len(data) > 0:
            for SchoolId,SchoolName,SchoolTelNo in data[0]:
                info=SchoolInfo()
                info.SchoolId=SchoolId
                info.SchoolName=SchoolName
                info.SchoolTelNo=SchoolTelNo
                students.append(info)
        return students
 
    def show(self)-> int:
        """
        :return:
        """
        students = []
        k=-1
        data = self.dal().selectSql()
        if len(data) > 0:
            for SchoolId,SchoolName,SchoolTelNo in data[0]:
                info = SchoolInfo()
                info.SchoolId = SchoolId
                info.SchoolName = SchoolName
                info.SchoolTelNo = SchoolTelNo
                students.append(info)
                k=1
 
            print("┌{:<10s}┬{:<70s}┬{:<20s}┐".format("─" * 10, "─" * 70, "─" * 20))
            print(self._field.Title)
            print("├{:<10s}┼{:<70s}┼{:<20s}┤".format("═"*10, "═"*70, "═"*20))
            i=1
            for info in data:
                print("│{:<10s}│{:<70s}│{:<20s}│".format(info.SchoolId.center(10), " {}".format(info.SchoolName.strip()),
                                                         info.SchoolTelNo.center(20)))  # rjust  ljust
                if i<len(data):
                    print("├{:<10s}┼{:<70s}┼{:<20s}┤".format("─" * 10, "─" * 70, "─" * 20))
                i=i+1
 
            print("└{:<10s}┴{:<70s}┴{:<20s}┘".format("─" * 10, "─" * 70, "─" * 20))
 
 
        return k
 
 
    def selectSqlCount(cls) -> int:
        """
        查询数据 总数
        :return:
        """
        #print(cls.dal().selectSqlCount()[0][0])
        total=cls.dal().selectSqlCount()[0][0]
        return total
 
    def Count(self) -> int:
        """
        查询数据 总数
        :return:
        """
        total=self.dal().selectSqlCount()[0][0]
        return total
 
    def selectSqlOrder(cls, order: str) -> list[SchoolInfo]:
        """
        元组数据
        :param order: SchoolName desc/asc
        :return:
        """
        students=[]
        data = cls.dal().selectSqlOrder(order)
        if len(data) > 0:
            for SchoolId,SchoolName,SchoolTelNo in data[0]:
                info=SchoolInfo()
                info.SchoolId=SchoolId
                info.SchoolName=SchoolName
                info.SchoolTelNo=SchoolTelNo
                students.append(info)
        return students
 
 
    def selectSort(cls,field:str,isOrder:bool)->list[SchoolInfo]:
        """
        :param field SchoolId
        :param order:  desc/asc
        :return:
        """
        students=[]
        data = cls.dal().selectSort(field,isOrder)
        if len(data) > 0:
            for SchoolId, SchoolName, SchoolTelNo in data[0]:
                info = SchoolInfo()
                info.SchoolId = SchoolId
                info.SchoolName = SchoolName
                info.SchoolTelNo = SchoolTelNo
                students.append(info)
        return students
 
    def display(self,data:list[SchoolInfo]):
        """
        :param data:
        :return:
        """
        if len(data) > 0:
            print("┌{:<10s}┬{:<70s}┬{:<20s}┐".format("─" * 10, "─" * 70, "─" * 20))
            print(self._field.Title)
            print("├{:<10s}┼{:<70s}┼{:<20s}┤".format("═"*10, "═"*70, "═"*20))
            i=1
            for info in data:
                print("│{:<10s}│{:<70s}│{:<20s}│".format(info.SchoolId.center(10), " {}".format(info.SchoolName.strip()),
                                                         info.SchoolTelNo.center(20)))  # rjust  ljust
                if i<len(data):
                    print("├{:<10s}┼{:<70s}┼{:<20s}┤".format("─" * 10, "─" * 70, "─" * 20))
                i=i+1
 
            print("└{:<10s}┴{:<70s}┴{:<20s}┘".format("─" * 10, "─" * 70, "─" * 20))
 
    def selectIdSql(cls,SchoolId:str) -> list[SchoolInfo]:
        """
        :param SchoolId:ID
        :return:
        """
        students = []
        data = cls.dal().selectIdSql(SchoolId)
        #print(data)
        if len(data)>0:
            for SchoolId,SchoolName,SchoolTelNo in data[0]:
                info = SchoolInfo()
                info.SchoolId = SchoolId
                info.SchoolName = SchoolName
                info.SchoolTelNo = SchoolTelNo
                students.append(info)
        return students
 
 
    def selectProc(cls) -> list[SchoolInfo]:
        """
        :return:
        """
        students=[]
        data = cls.dal().selectProc()
        #print(data)
        if len(data) > 0:
            for SchoolId,SchoolName,SchoolTelNo in data:
                info = SchoolInfo()
                info.SchoolId = SchoolId
                info.SchoolName = SchoolName
                info.SchoolTelNo = SchoolTelNo
                students.append(info)
        return students
 
    def selectIdProc(cls,StudentId:str) -> list[SchoolInfo]:
        """
        :param StudentId:
        :return:
        """
        students = []
        data = cls.dal().selectIdProc(StudentId)
        if len(data) > 0:
            for SchoolId,SchoolName,SchoolTelNo in data:
                info = SchoolInfo()
                info.SchoolId = SchoolId
                info.SchoolName = SchoolName
                info.SchoolTelNo = SchoolTelNo
                students.append(info)
        return students
 
    def addSql(cls,info:SchoolInfo) -> int:
        """
        :param info:实体类
        :return:
        """
        return cls.dal().addSql(info)
 
 
    def add(self,info:SchoolInfo) -> int:
        """
        :param info:实体类
        :return:
        """
        return self.dal().addSql(info)
 
 
    def addProc(cls,info:SchoolInfo) -> int:
        """
        :param info:实体类
        :return:
        """
        #print(info)
        return cls.dal().addProc(info)
 
    def addOutProc(cls,info:SchoolInfo)->int:
        """
        :param info: 实体类
        :return: 返回增加的ID
        """
        print(info)
        return cls.dal().addOutProc(info)
 
    def editSql(cls,info:SchoolInfo) -> int:
        """
        :param info:实体类
        :return:
        """
        #print(info)
        return cls.dal().editSql(info)
 
    def edit(self,info:SchoolInfo) -> int:
        """
        :param info:实体类
        :return:
        """
        #print(info)
        return self.dal().editSql(info)
 
    def editProc(cls, info: SchoolInfo) -> int:
        """
        :param info:实体类
        :return:
        """
        return cls.dal().editProc(info)
 
    def delSql(cls, SchoolId: str) -> int:
        """
        :param SchoolId:
        :return:
        """
        return cls.dal().delSql(SchoolId)
 
    def delinfo(self, SchoolId: str) -> int:
        """
        :param SchoolId:
        :return:
        """
        return self.dal().delSql(SchoolId)
 
    def delProc(cls, SchoolId:str) -> int:
        """
        :param SchoolId:
        :return:
        """
        return cls.dal().delProc(SchoolId)
 

  

调用:

    sc=SchoolBll()
    for li in sc.selectSql():
        print(li.SchoolId,li.SchoolName,li.SchoolTelNo)

  

标签:info,Layer,SchoolId,return,Python,postgreSQL17.0,self,def,cls
From: https://www.cnblogs.com/geovindu/p/18544675

相关文章

  • canny 算法 python实现, 双边滤波--自适应阈值改进--形态学操作
    #-*-coding:utf-8-*-importnumpyasnpimportcv2importosimportcsv#高斯滤波defsmooth(image,sigma=1.4,length=5):#Computegaussianfilterk=length//2gaussian=np.zeros([length,length])foriinrange(length):for......
  • Python中的面向对象编程,类,对象,封装,继承,多态
    一、面向对象编程1.面向过程和面向对象面向过程和面向对象都是一种编程方式,只不过再设计上有区别。面向过程C语言细分成每一个过程优点:简单直观、性能高效、代码简洁。缺点:不易维护、不易扩展、代码重用性低。面向对象python、java、C++要使用某个功能,直接找到对应的......
  • python毕设网上商城系统的设计与实现程序+论文
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容一、选题背景关于网上商城系统的研究,现有研究多以大型商业平台为对象,以特定框架如SSM框架下的Java实现为主,而专门针对Python实现的网上商城系统研......
  • 【最新原创毕设】面向课堂教学的智能课堂点名系统+09531(免费领源码)可做计算机毕业设计
    摘要本文旨在设计和实现一个基于智能课堂点名系统的智能助手。随着高校招生规模的不断扩大和信息化技术的发展,为教师提供一款便捷、全面的点名系统具有重要意义。本系统通过整合校园各项服务资源和功能,旨在帮助教师和学生更好地适应智能课堂,提供全方位的指导和支持。本文......
  • (2024最新毕设合集)基于SpringBoot的广州糖水甜品店推荐系统-28495|可做计算机毕业设计J
    摘要随着人们生活水平的提高和饮食习惯的多样化,甜品在日常生活中扮演着越来越重要的角色。特别是在中国南方地区,甜品店和糖水店已经成为人们经常光顾的地方,而广州作为美食之都,拥有众多具有独特风味的糖水甜品店。然而,由于市场竞争激烈,消费者往往面临选择困难,需要花费大量时间......
  • 【python系列】python之变量赋值操作
    1.前言变量是什么?我们学任何什么东西,都要从定义入手,只有清晰且无歧义的定义,才能真正理解这个概念是什么意思。维基百科的定义:在数学、物理学中,变量(variable)又称变数,是表达式或公式中,没有固定的值而可以变动的数或量;该数或量可以是随意的,也可能是未指定或未定的。——Wik......
  • Python爬虫知识体系-----正则表达式-----持续更新
    数据科学、数据分析、人工智能必备知识汇总-----Python爬虫-----持续更新:https://blog.csdn.net/grd_java/article/details/140574349文章目录一、正则基础1.为什么使用正则2.正则与re模块简介二、正则表达式1.匹配单个字符与数字2.限定符3.定位符4.选择匹配符5.......
  • python实现赛博宠物(纯代码无需素材)
    1、创作背景    今天如往常一样来上班,一进公司就看见财务小姐姐闷闷不乐,就走过去跟她聊天,她说她很想养一只小狗,但是家里面不同意,怕把家里弄得乱七八糟。看着小姐姐悲伤的样子,我恏大力最舍不得小姐姐不开熏,所以我恏大力就要出来帮助美丽的财务小姐姐咯。2、技术选择......
  • 忽悠财务小姐姐神器(python实现3D爱心)
    1、设计背景        最近在网上看到了很多粒子爱心的python源码,所以就突发奇想也做一个爱心,但是粒子爱心这么多人做了就没什么意思了,那我就来做一个3D粉嫩旋转爱心,要的就是别出心裁,出人意料。这发给财务小姐姐,我恏大力的春天不就来了!!2、使用技术        这......
  • 网页全终端安防视频流媒体播放器EasyPlayer.js无插件H5播放器包含的直播协议支持(封装
    EasyPlayer.jsH5播放器,是一款能够同时支持HTTP、HTTP-FLV、HLS(m3u8)、WS、WEBRTC、FMP4视频直播与视频点播等多种协议,支持H.264、H.265、AAC、G711A、Mp3等多种音视频编码格式,支持MSE、WASM、WebCodec等多种解码方式,支持Windows、Linux、Android、iOS全平台终端的H5播放器,使用简单......