Exemplo n.º 1
0
def docment_manage_fileauth_cfg(request):
    log = public.logger
    form_var = public.req_body['form_var']

    try:
        cur = connection.cursor()  # 创建游标

        file_type = form_var.get('file_type')
        if not file_type:
            public.respcode, public.respmsg = "310310", "请先选择文件类型!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo
        form_var['read_cfginfo'] = str(form_var.get('read_cfginfo'))
        form_var['write_cfginfo'] = str(form_var.get('write_cfginfo'))

        flag, msg = public_db.insert_or_update_table(
            cur, 'yw_workflow_document_manage_cfg', **form_var)
        if not flag:
            public.respcode, public.respmsg = "310310", msg
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo
        # sql = "select 1 from yw_workflow_document_manage_cfg where file_type=%s"
        # cur.execute(sql, file_type)
        # row = cur.fetchone()
        # if row:  # 有数据, 更新
        #     sql = "update yw_workflow_document_manage_cfg set read_cfgtype=%s,read_cfginfo=%s, write_cfgtype=%s,write_cfginfo=%s  " \
        #           "where file_type=%s"
        # else:  # 无数据,插入
        #     sql = "insert into yw_workflow_document_manage_cfg(read_cfgtype,read_cfginfo,write_cfgtype,write_cfginfo, file_type) " \
        #           "values(%s, %s, %s, %s, %s)"
        # cur.execute(sql,
        #             (form_var.get('read_cfgtype'), str(form_var.get('read_cfginfo')), form_var.get('write_cfgtype'),
        #              str(form_var.get('write_cfginfo')), file_type))
    except Exception as ex:
        log.error("更新数据失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "100010", "更新数据失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())

    else:
        public.respcode, public.respmsg = "000000", "交易成功!"
        json_data = {
            "HEAD": public.resphead_setvalue(),
            "BODY": {
                "form_var": form_var
            }
        }
        s = json.dumps(json_data,
                       cls=public.JsonCustomEncoder,
                       ensure_ascii=False)
        public.respinfo = HttpResponse(s)
    finally:
        cur.close()  # 关闭游标

    return public.respinfo
Exemplo n.º 2
0
def boxing_begin_set(request):
    log = public.logger
    body = public.req_body
    try:
        form_var = body.get('form_var')
        orderid = form_var.get('order_id')
        modelid = form_var.get('model_id')

        cur = connection.cursor()  # 创建游标

        sql = "select box_code, tray_code, model_box_seq, model_tray_seq, state from yw_project_boxing_info " \
              "where order_id=%s and model_id=%s "
        cur.execute(sql, (orderid, modelid))
        row = cur.fetchone()
        if not row:
            cur.close()
            public.respcode, public.respmsg = "554901", "此工单没有待装箱的模块!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo
        now_box_code = row[0]
        now_tray_code = row[1]
        model_box_seq = row[2]
        model_tray_seq = row[3]
        db_state = row[4]
        if db_state == '1':
            cur.close()
            public.respcode, public.respmsg = "554903", "此模块ID已装箱!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo

        fix_out = True
        sql = "insert into yw_project_boxing_info_lasttray(order_id, box_code,tray_code,model_id, fix_out,errinfo ) " \
              "values( '%s', '%s', '%s', '%s', '%s', '%s')" \
              % (orderid, now_box_code, now_tray_code, modelid, fix_out, '管理台设置装箱数据')
        cur.execute(sql)

        cur.close()

        form_var['box_code'] = now_box_code
        form_var['tray_code'] = now_tray_code
        form_var['model_box_seq'] = model_box_seq
        form_var['model_tray_seq'] = model_tray_seq
    except Exception as ex:
        log.error("交易失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        cur.close()
        public.respcode, public.respmsg = "300010", "交易失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {"HEAD": public.resphead_setvalue(), "BODY": body}
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 3
0
def get_menu_info(request):
    log = public.logger
    body = public.req_body
    menuid = body.get('menu_id')
    if not menuid:
        public.respcode, public.respmsg = "100112", "menu_id不可为空!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    try:
        cur = connection.cursor()  # 创建游标
        sql = "select a.menu_id, a.menu_name, a.is_run_menu, a.menu_desc, a.order_id, a.app_id, a.menu_type, a.menu_path, " \
              "a.menu_icon, a.is_enable, a.above_menu_id " \
              "from sys_menu a  where a.menu_id =%s "
        log.info("查询菜单详情:" + sql % menuid, extra={'ptlsh': public.req_seq})
        cur.execute(sql, (menuid))
        row = cur.fetchone()
        if not row:
            cur.close()
            log.info("对应的MENUID不存在!", extra={'ptlsh': public.req_seq})
            public.respcode, public.respmsg = "100111", "对应的MENUID不存在!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo

        menuinfo = {}
        menuinfo['menu_id'] = str(row[0])
        menuinfo['menu_name'] = row[1]
        menuinfo['menu_desc'] = row[3]
        menuinfo['menu_seq'] = row[4]  #排序号
        menuinfo['menu_appid'] = row[5]
        menuinfo['menu_type'] = row[6]  #菜单类型 目录,自定义等。。
        menuinfo['menu_path'] = row[7]  # 菜单路径(自定义路径)
        menuinfo['menu_icon'] = row[8]  # 菜单图标
        menuinfo['is_active'] = public.Y2True(row[9])
        menuinfo['above_menu_id'] = row[10]  # 上级菜单ID

        cur.close()

    except Exception as ex:
        log.error("菜单信息查询失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "100200", "菜单信息查询失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "menuinfo": menuinfo,
        },
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 4
0
def transfer_attend_manage_groupcfg(request):
    log = public.logger
    body = public.req_body
    select_key = body.get('select_key')
    form_var = body.get('form_var')
    group_list = form_var.get('group_list')
    try:
        transfer = []  # 全部数据, 数据变量
        transfer_data = []  # 已选中数据,绑定变量

        if not group_list:
            public.respcode, public.respmsg = "310310", "请先选择考勤組!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo

        cur = connection.cursor()  # 创建游标
        # sql = "SELECT user_id,user_name FROM sys_user  WHERE state='1'"
        sql = "SELECT job_num,name from yw_workflow_attend_mx GROUP BY job_num"
        cur.execute(sql)
        rows = cur.fetchall()
        for item in rows:
            transfer.append({
                "key": item[0],
                "label": str(item[1]),
                "disabled": False
            })
        sql = "SELECT user_id from yw_workflow_attend_group_user where group_id = %s"
        log.info("group_list: [%s]" % group_list)
        cur.execute(sql, group_list)
        row = cur.fetchone()
        if row:
            for subitem in eval(row[0]):
                transfer_data.append(subitem)
        cur.close()

        form_var['userinfo_option'] = transfer
        form_var['userinfo'] = transfer_data
    except Exception as ex:
        log.error("生成穿梭框数据失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "303010", "生成穿梭框数据失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())
        return '' ''

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "form_var": form_var,
        }
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 5
0
def export_abnormal_detail_excel(request):
    """导出考勤异常详单"""
    log = public.logger
    body = public.req_body
    form_var = body['form_var']
    month_id = form_var.get('month_id')
    if not month_id:
        public.respcode, public.respmsg = "310310", "请先选择考勤月份!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    try:
        sql = "select id,state from yw_workflow_attend_report_mx where substr(natural_day,1,7) = '%s'" % month_id
        cur = connection.cursor()
        cur.execute(sql)
        rows = cur.fetchall()
        if not rows:
            public.respcode, public.respmsg = "310314", "该月尚未生成报表!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo
        else:
            id_list = []
            abnormal_list = ['迟到', '早退', '事假', '病假', '丧假', '产假', '陪产假', '待处理']
            for row in rows:
                attend_state = eval(row[1])
                if set(attend_state).intersection(set(abnormal_list)):
                    id_list.append(row[0])
            abnormal_sql = "select department,job_num,user_name,natural_day,in_time,out_time,state " \
                           "from yw_workflow_attend_report_mx " \
                           "where id in %s" % str(tuple(id_list))

            file_name = month_id + '_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S") + '考勤异常记录.xlsx'
            full_file_name = public.localhome + '/static/filedown/' + file_name
            # 导出Excel
            pubfunc.export_excel(full_file_name, abnormal_sql)
            form_var['file_download_path'] = '/static/filedown/' + file_name

    except Exception as ex:
        log.error(ex)
        # tr.close()
        log.error('导出数据到excel文件错误', exc_info=True)
        data = {
            "respcode": "000000",
            "respmsg": "导出数据到excel文件错误",
            "trantype": public.req_head.get('trantype', None)
        }
    else:
        public.respcode, public.respmsg = "000000", "交易成功!"
        json_data = {
            "HEAD": public.resphead_setvalue(),
            "BODY": {
                "form_var": form_var
            }
        }
        s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
        public.respinfo = HttpResponse(s)
        return public.respinfo
Exemplo n.º 6
0
def docment_copy_by_seclass(request):
    """文档三级目录复制"""
    log = public.logger
    body = public.req_body
    form_var = body['form_var']
    try:
        company = form_var.get('company')
        seclasstype = form_var.get('seclasstype')
        if not company:
            public.respcode, public.respmsg = "310314", "公司不可为空!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo
        if not seclasstype:
            public.respcode, public.respmsg = "310314", "二级文档类别不可为空!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo
        cur = connection.cursor()  # 创建游标
        # 查询该公司下属二级目录
        sql = "select class_name,class_spell from yw_workflow_document_classtype where class_top = %s and class_rank=3 "
        cur.execute(sql, seclasstype)
        rows = cur.fetchall()
        if not rows:
            public.respcode, public.respmsg = "310318", "该文档类别下没有可供复制的三级目录!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo
        dict_list = [{'class_name': k, 'class_spell': v} for k, v in rows]
        form_var['trdclasslist'] = dict_list
    except Exception as ex:
        log.error("更新数据失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "100010", "查询数据失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())

    else:
        public.respcode, public.respmsg = "000000", "交易成功!"
        json_data = {
            "HEAD": public.resphead_setvalue(),
            "BODY": {
                "form_var": form_var
            }
        }
        s = json.dumps(json_data,
                       cls=public.JsonCustomEncoder,
                       ensure_ascii=False)
        public.respinfo = HttpResponse(s)
    finally:
        cur.close()  # 关闭游标

    return public.respinfo
Exemplo n.º 7
0
def get_table_info(request):
    log = public.logger
    body = public.req_body  # 请求报文体
    tablename = body.get('tablename')
    if not tablename:
        public.respcode, public.respmsg = "100101", "表名必输!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    cur = connection.cursor()
    # 根据表名获取表信息
    tablename = tablename.upper()
    try:
        sql = "SELECT LOWER(column_name), column_comment FROM information_schema.columns " \
              "WHERE UPPER(table_name) = UPPER(%s) order by ordinal_position asc"
        # log.info(sql % tablename)
        cur.execute(sql, tablename)
        rows = cur.fetchall()

        table_field = []

        loopid = 0
        for item in rows:
            tableitem = {}
            loopid = loopid + 1
            tableitem["field_id"] = item[0]
            tableitem["field_name"] = item[1]
            table_field.append(tableitem)
        cur.close()
    except Exception as ex:
        log.error("获取数据表信息失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "100102", "获取数据表信息失败!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "table_field": table_field
        }
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 8
0
def get_workflow_cfg_info(request):
    log = public.logger
    body = public.req_body
    formid = body.get("form_id")

    if not formid:
        public.respcode, public.respmsg = "110221", "表单ID不可为空!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    try:
        workflow_info = []
        cur = connection.cursor()  # 创建游标
        sql = "select wf_id, wf_notes, wf_prev,wf_type,wf_cfg from sys_workflow_node_cfg where form_id=%s "
        cur.execute(sql, formid)
        rows = cur.fetchall()
        for item in rows:
            wfinfo = {}
            wfinfo['wf_id'] = item[0]
            wfinfo['wf_notes'] = item[1]
            wfinfo['wf_prev'] = item[2]
            wfinfo['wf_type'] = item[3]
            if item[4]:
                wfinfo['wf_cfg'] = eval(item[4])
            else:
                wfinfo['wf_cfg'] = {}
            workflow_info.append(wfinfo)
        cur.close()  # 关闭游标

    except Exception as ex:
        log.error("交易失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "workflow_info": workflow_info,
        },
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 9
0
def funcmodel(request):
    log = public.logger

    try:

        cur = connection.cursor()  # 创建游标

        cur.close()

    except Exception as ex:
        log.error("获取数据表信息失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "100100", "获取数据表信息失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {},
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 10
0
        def GetNowTrayCode(db_maxtray_num):
            # 获取当前正在装箱的托盘号
            sql = "select tray_code, state from yw_project_boxing_info_lasttray " \
                  "where order_id='%s' order by id desc limit 1" % ( body.get('order_id') )
            cur.execute(sql)
            row = cur.fetchone()
            if row:
                db_last_tray_code = row[0]
                # if not row[1]: #管理台设置的当前开始装箱托盘号
                #     db_last_tray_code = row[0]
                # else:
                #     db_last_tray_code = row[0] + 1  #自动包装程序运行的托盘号,是指最后的托盘号。
                #当前托盘已装数量
                sql = "select count( distinct model_id ) from yw_project_boxing_info_autoput_detail " \
                      "where order_id='%s' and tray_code='%s' " % ( body.get('order_id'), db_last_tray_code )
                cur.execute(sql)
                row = cur.fetchone()
                db_nowbox_num = row[0]
                if db_nowbox_num >= db_maxtray_num:
                    db_last_tray_code = db_last_tray_code + 1
            else:  #无数据,查询box_info表当前正在装的托盘号
                # 查询最近正在装的一个托盘
                sql = "select tray_code from yw_project_boxing_info where order_id='%s' and state='0' " \
                      "order by tray_code asc limit 1 " % (body.get('order_id'))
                cur.execute(sql)
                row = cur.fetchone()
                if not row:
                    cur.close()
                    public.respcode, public.respmsg = "553942", "此订单没有待装箱的模块!"
                    public.respinfo = HttpResponse(public.setrespinfo())
                    return public.respinfo
                db_last_tray_code = row[0]
                db_nowbox_num = 0

            return db_last_tray_code, db_nowbox_num
Exemplo n.º 11
0
def get_crud_list(request):
    log = public.logger
    try:
        cur = connection.cursor()  # 创建游标
        sql = "select app_id, app_name from sys_crud_cfg_head order by upd_time desc"
        cur.execute(sql)
        rows = cur.fetchall()
        crud_list = []
        for item in rows:
            tableitem = {}
            tableitem["value"] = str(item[0])
            tableitem["lable"] = str(item[0]) + '  ' + str(item[1])
            crud_list.append(tableitem)
        cur.close()
    except Exception as ex:
        log.error("获取增删改查配置信息失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "100103", "获取增删改查配置信息失败!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "crud_list": crud_list
        }
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 12
0
def export_report_excel(request):
    """导出考勤报表"""
    log = public.logger
    body = public.req_body
    form_var = body['form_var']
    month_id = form_var.get('month_id')
    if not month_id:
        public.respcode, public.respmsg = "310310", "请先选择考勤月份!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    try:
        sql = "select month_id,department,user_name,job_num,chid,zaot,gonx,tx,shij,bingj,chuc,sangj,cj,pcj,attend_days," \
              "work_days from yw_workflow_attend_report where month_id = '%s'" % month_id
        cur = connection.cursor()
        cur.execute(sql)
        row = cur.fetchone()
        if not row:
            public.respcode, public.respmsg = "310314", "该月尚未生成报表!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo
        file_name = month_id + '_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S") + '考勤报表.xlsx'
        full_file_name = public.localhome + '/static/filedown/' + file_name
        # 导出Excel
        pubfunc.export_excel(full_file_name, sql)
        form_var['file_download_path'] = '/static/filedown/' + file_name

    except Exception as ex:
        log.error(ex)
        # tr.close()
        log.error('导出数据到excel文件错误', exc_info=True)
        data = {
            "respcode": "000000",
            "respmsg": "导出数据到excel文件错误",
            "trantype": public.req_head.get('trantype', None)
        }
    else:
        public.respcode, public.respmsg = "000000", "交易成功!"
        json_data = {
            "HEAD": public.resphead_setvalue(),
            "BODY": {
                "form_var": form_var
            }
        }
        s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
        public.respinfo = HttpResponse(s)
        return public.respinfo
Exemplo n.º 13
0
def attend_schedule_save(request):
    log = public.logger
    body = public.req_body
    form_var = body['form_var']
    try:
        cur = connection.cursor()  # 创建游标

        month_id = form_var.get('month_id')
        group_list = form_var.get('group_list')
        # 插入休息日字段
        day_list_option = form_var.get('day_list_option')
        day_list = form_var.get('day_list')
        month_day_list = []
        for item in day_list_option:
            month_day_list.append(item.get('key'))
        res_day_list = set(month_day_list).difference(set(day_list))
        res_day_list = list(res_day_list)
        sql_value = (str(day_list), str(res_day_list), form_var.get('work_time'), form_var.get('closing_time'),
                     form_var.get('am_closing'), form_var.get('pm_start'),
                     form_var.get('group_list'), form_var.get('month_id'))
        log.info("============STR_LIST===========")
        log.info(str(form_var.get('day_list')))
        if month_id and group_list:
            sql = 'select 1 from yw_workflow_attend_group_cfg where group_id = %s and month_id = %s'
            cur.execute(sql, (form_var.get('group_list'), form_var.get('month_id')))

            row = cur.fetchone()
            if row:  # 有数据, 更新
                sql = "update yw_workflow_attend_group_cfg set work_day=%s, rest_day=%s,work_time=%s," \
                      "closing_time=%s,am_closing_time=%s,pm_start_time=%s where group_id = %s and month_id = %s"
            else:  # 无数据,插入
                sql = "insert into yw_workflow_attend_group_cfg (work_day,rest_day,work_time,closing_time," \
                      "am_closing_time,pm_start_time, group_id, month_id) values (%s, %s, %s, %s, %s, %s, %s, %s)"
        else:
            pass
        log.info(sql, sql_value)

        cur.execute(sql, sql_value)
    except Exception as ex:
        log.error("更新数据失败!" + str(ex), exc_info=True, extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info()
        public.respcode, public.respmsg = "100010", "更新数据失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())

    else:
        public.respcode, public.respmsg = "000000", "交易成功!"
        json_data = {
            "HEAD": public.resphead_setvalue(),
            "BODY": {
                "form_var": form_var
            }
        }
        s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
        public.respinfo = HttpResponse(s)
    finally:
        cur.close()  # 关闭游标

    return public.respinfo
Exemplo n.º 14
0
def delete_menu_info(request):
    log = public.logger
    body = public.req_body
    menuid = body.get('menu_id')
    if not menuid:
        public.respcode, public.respmsg = "100312", "menu_id不可为空!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    try:
        cur = connection.cursor()  # 创建游标
        sql = "select menu_id,menu_name from sys_menu where above_menu_id = %s "  #查看是否有下级菜单
        log.info("查看是否有下级菜单:" + sql % menuid, extra={'ptlsh': public.req_seq})
        cur.execute(sql, (menuid))
        row = cur.fetchone()
        if row:
            cur.close()
            public.respcode, public.respmsg = "100316", "请先删除下级菜单!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo

        sql = "delete from sys_menu where menu_id=%s "  # 查看是否有下级菜单
        log.info("删除菜单:" + sql % menuid, extra={'ptlsh': public.req_seq})
        cur.execute(sql, (menuid))

        cur.close()

    except Exception as ex:
        log.error("菜单信息删除失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "100300", "菜单信息删除失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {},
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 15
0
def order_detail_add(request):
    log = public.logger
    body = public.req_body
    form_var = body.get('form_var')
    if not form_var:
        public.respcode, public.respmsg = "387711", "上送数据异常!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    try:
        cur = connection.cursor()  # 创建游标

        sql = "insert into yw_workflow_work_order(start_time,sponsor,  order_type, receiver, order_urgent_type, " \
              "receiving_department, require_completion_time, requirments, requirements_ziliao, remarks, state) " \
              "values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '0')"
        cur.execute(sql, (form_var.get('start_time'), public.user_id,
                          form_var.get('order_type'), form_var.get('receiver'),
                          form_var.get('order_urgent_type'),
                          form_var.get('receiving_department'),
                          form_var.get('require_completion_time'),
                          form_var.get('requirments'),
                          str(form_var.get('requirements_ziliao')),
                          form_var.get('remarks')))
        form_var['state_info'] = '0'

        cur.close()

    except Exception as ex:
        log.error("交易失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.respcode, public.respmsg = "999999", str(ex)
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": body,
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 16
0
def get_org_list( request ):
    log = public.logger
    body = public.req_body
    # 获取菜单角色列表,--菜单配置时使用
    def GetCfgOrgTreeData( above_org_id ):
        log = public.logger
        OrgTreeData = []

        sql = "select org_id, org_name from sys_org where above_org_id='%s' and org_state='1' "  % ( above_org_id )
        # log.info("获取机构信息列表:" + sql, extra={'ptlsh': public.req_seq})
        cur.execute(sql)
        rows = cur.fetchall()
        for item in rows:
            orginfo = {}
            org_id = str(item[0])
            orginfo['id'] = org_id
            orginfo['label'] = item[1]

            tempchild = GetCfgOrgTreeData(org_id)
            if len(tempchild) > 0:
                orginfo['children'] = tempchild

            OrgTreeData.append(orginfo)

        # log.info("OrgTreeData" + str(OrgTreeData))
        # 返回结果
        return OrgTreeData

    try:
        cur = connection.cursor()
        orglist = GetCfgOrgTreeData( 'root' )
        orgselect=[]
        form_data=body.get('form_data')
        if form_data:
            userid = form_data.get('user_id')
        else:
            userid = ''
        #获取用户已经拥有的机构
        sql=" select org_id from sys_user_org where user_id='%s' " % userid
        log.info(sql)
        cur.execute(sql)
        rows=cur.fetchall()
        for item in rows:
            orgselect.append(item[0])
        cur.close()

    except Exception as ex:
        log.error("交易失败!"+str(ex), exc_info=True, extra={'ptlsh':public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info()
        public.respcode, public.respmsg = "300200", "交易失败!" + str(ex)
        public.respinfo = HttpResponse( public.setrespinfo() )
        return '' ''

    return orglist, orgselect
Exemplo n.º 17
0
def erp_check_everyday_getdata(request):
    log = public.logger
    body = public.req_body
    form_data = body.get('form_data')
    if not form_data:  #未上传数据,估计是新增
        selectd_data = {}
        form_data = {}
    else:
        selectd_data = form_data.get('selectd_data')

    try:
        cur = connection.cursor()  # 创建游标

        # 赋值返回数据
        data = {}
        if selectd_data:
            selectd = selectd_data[0]
            data['id'] = selectd.get('id')
            data['check_name'] = selectd.get('check_name')
            data['check_date'] = selectd.get('check_date')
            data['check_sql'] = selectd.get('check_sql')
            data['check_state'] = selectd.get('check_state')
            data['check_msg'] = selectd.get('check_msg')
        cur.close()

        data["check_state_options"] = [{
            "key": "0",
            "value": "停用"
        }, {
            "key": "1",
            "value": "启用"
        }]
        # submit_power = {"show": True, "disabled": False} #放开提交按钮

    except Exception as ex:
        log.error("生成数据失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "300010", "生成数据失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "form_var": data,
        }
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 18
0
def workflow_get_formfield_info(request):
    log = public.logger
    body = public.req_body
    formid = body.get("form_id")

    if not formid:
        public.respcode, public.respmsg = "110221", "表单ID不可为空!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    try:
        cur = connection.cursor()  # 创建游标
        sql = "select field_id, field_name from sys_form_cfg_fieldlist where form_id=%s " \
              "and comp_type in ('textarea', 'input', 'datetime', 'select', 'radio', 'date')"
        cur.execute(sql, formid)
        rows = cur.fetchall()
        field_list = []
        for item in rows:
            field_list.append({"key": item[0], "value": item[1]})

        cur.close()

    except Exception as ex:
        log.error("交易失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "field_list": field_list,
        },
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 19
0
def attend_manage_group_cfg(request):
    log = public.logger
    form_var = public.req_body['form_var']
    try:
        cur = connection.cursor()  # 创建游标
        group_list = form_var.get('group_list')
        if not group_list:
            public.respcode, public.respmsg = "310310", "请先选择考勤組!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo

        sql = "select 1 from yw_workflow_attend_group_user where group_id=%s"
        cur.execute(sql, group_list)
        row = cur.fetchone()
        if row:  # 有数据, 更新
            sql = "update yw_workflow_attend_group_user set user_id=%s where group_id=%s"
        else:  # 无数据,插入
            sql = "insert into yw_workflow_attend_group_user (user_id, group_id) values (%s, %s)"
        log.info(sql, (str(form_var.get('userinfo')), group_list))
        cur.execute(sql, (str(form_var.get('userinfo')), group_list))
    except Exception as ex:
        log.error("更新数据失败!" + str(ex), exc_info=True, extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info()
        public.respcode, public.respmsg = "100010", "更新数据失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())

    else:
        public.respcode, public.respmsg = "000000", "交易成功!"
        json_data = {
            "HEAD": public.resphead_setvalue(),
            "BODY": {
                "form_var": form_var
            }
        }
        s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
        public.respinfo = HttpResponse(s)
    finally:
        cur.close()  # 关闭游标

    return public.respinfo
Exemplo n.º 20
0
def workflow_get_user_list(request):
    log = public.logger
    body = public.req_body
    # formid=body.get("form_id")
    #
    # if not formid:
    #     public.respcode, public.respmsg = "110221", "表单ID不可为空!"
    #     public.respinfo = HttpResponse(public.setrespinfo())
    #     return public.respinfo

    try:
        cur = connection.cursor()  # 创建游标
        sql = "select user_id, user_name from sys_user where state='1' "
        cur.execute(sql)
        rows = cur.fetchall()
        user_list = []

        # 先初始化几个特殊的用户
        user_list.append({
            "key": "org_leader",
            "value": 'org_leader' + '-' + '部门负责人'
        })

        for item in rows:
            user_list.append({
                "key": item[0],
                "value": str(item[0]) + '-' + item[1]
            })

        cur.close()

    except Exception as ex:
        log.error("交易失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "user_list": user_list,
        },
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 21
0
def erp_check_everyday_getlist(request):
    log = public.logger
    body = public.req_body
    form_var = body.get('form_var')
    form_data = body.get('form_data')
    try:
        cur = connection.cursor()  # 创建游标
        # 获取线别字典
        tableData = []
        sql = "select id,check_name,check_date,check_sql,check_state,check_msg from yw_lqerp_check_everyday order by id desc"
        cur.execute(sql)
        rows = cur.fetchall()
        for item in rows:
            dataitem = {}
            dataitem['id'] = item[0]
            dataitem['check_name'] = item[1]
            dataitem['check_date'] = item[2]
            dataitem['check_sql'] = item[3]
            dataitem['check_state'] = item[4]
            dataitem['check_msg'] = item[5]
            tableData.append(dataitem)
        cur.close()

        submit_power = {"show": True, "disabled": False}  #放开提交按钮

    except Exception as ex:
        log.error("生成数据失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "300010", "生成数据失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "form_var": {
                "tableData": tableData,
                "submit_power": submit_power,
            },
        }
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 22
0
def erp_check_everyday_savedata(request):
    log = public.logger
    body = public.req_body
    form_var = body.get('form_var')

    try:
        cur = connection.cursor()  # 创建游标

        if form_var.get('id'):
            sql = "update yw_lqerp_check_everyday set check_name=%s,check_date=%s,check_sql=%s,check_state=%s," \
                  "check_msg=%s where id=%s "
            cur.execute(
                sql, (form_var.get('check_name'), form_var.get('check_date'),
                      form_var.get('check_sql'), form_var.get('check_state'),
                      form_var.get('check_msg'), form_var.get('id')))
        else:
            sql = "insert into yw_lqerp_check_everyday(check_name,check_date,check_sql,check_state,check_msg) " \
                  "values(%s, %s, %s, %s, %s)"
            cur.execute(
                sql, (form_var.get('check_name'), form_var.get('check_date'),
                      form_var.get('check_sql'), form_var.get('check_state'),
                      form_var.get('check_msg')))

        cur.close()
    except Exception as ex:
        log.error("保存数据失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "300010", "保存数据失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "form_var": form_var,
        }
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 23
0
def Main_Proc( request ):
    public.respcode, public.respmsg = "999998", "交易开始处理!"
    log = public.logger
    sid = transaction.savepoint()
    func_name=public.tran_type+'(request)'
    if globals().get(public.tran_type):
        log.info('---[%s]-begin---' % (public.tran_type), extra={'ptlsh': public.req_seq})
        public.respinfo = eval(func_name)
        log.info('---[%s]-end----' % (public.tran_type), extra={'ptlsh': public.req_seq})
    else:
        public.respcode, public.respmsg = "100002", "trantype error!"
        public.respinfo = HttpResponse( public.setrespinfo() )
    if public.respcode=="000000":
        # 提交事务
        transaction.savepoint_commit(sid)
    # else:
    #     # 回滚事务
    #     transaction.savepoint_rollback(sid)
    return public.respinfo
Exemplo n.º 24
0
def workflow_cfg_create(request):
    log = public.logger
    body = public.req_body
    formid = body.get("form_id")

    if not formid:
        public.respcode, public.respmsg = "110221", "表单ID不可为空!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    wf_id = int(public.getintrandom(6))
    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "wf_id": wf_id,
        },
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 25
0
def test_boxdata_clear(request):
    log = public.logger
    body = public.req_body
    try:
        cur = connection.cursor()  # 创建游标
        orderid = 'MO2012A129'
        sql = "update yw_project_boxing_info set state='0' where order_id = '%s' " % orderid
        cur.execute(sql)

        sql = "delete from yw_project_meterread_test_info where Batch_Num = '%s' " % orderid
        cur.execute(sql)

        sql = "delete from yw_project_snid_detail where order_id = '%s' " % orderid
        cur.execute(sql)

        sql = "delete from yw_project_boxing_info_autoput_detail where order_id = '%s' " % orderid
        cur.execute(sql)

        sql = "delete from yw_project_boxing_info_lasttray where order_id = '%s' " % orderid
        cur.execute(sql)

        cur.close()

        body['form_var']['result'] = '清理数据完成!'
    except Exception as ex:
        log.error("交易失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        cur.close()
        public.respcode, public.respmsg = "300010", "交易失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {"HEAD": public.resphead_setvalue(), "BODY": body}
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 26
0
def transfer_userrole(request):
    log = public.logger
    body = public.req_body
    form_data = body.get('form_data')
    try:
        transfer = []  # 全部数据, 数据变量
        transferData = []  # 已选中数据,绑定变量

        cur = connection.cursor()  # 创建游标
        sql = "select role_id,role_name from sys_role where role_state='1' "
        cur.execute(sql)
        rows = cur.fetchall()
        for item in rows:
            transfer.append({
                "key": item[0],
                "label": item[0] + '-' + item[1],
                "disabled": False
            })

        #用户已拥有的角色
        if form_data.get('user_id'):
            sql = "select role_id from sys_user_role where user_id=%s"
            cur.execute(sql, form_data.get('user_id'))
            rows = cur.fetchall()
            for item in rows:
                transferData.append(item[0])

    except Exception as ex:
        log.error("生成穿梭框数据失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "303010", "生成穿梭框数据失败!" + str(ex)
        public.respinfo = HttpResponse(public.setrespinfo())
        return '' ''

    return transferData, transfer
Exemplo n.º 27
0
def workflow_get_org_list(request):
    log = public.logger
    body = public.req_body
    org_list = []
    try:
        cur = connection.cursor()

        sql = " select org_id, org_name from sys_org where org_state='1' "
        log.info(sql)
        cur.execute(sql)
        rows = cur.fetchall()
        for item in rows:
            org_list.append({
                "key": item[0],
                "value": str(item[0]) + '-' + item[1]
            })
        cur.close()

    except Exception as ex:
        cur.close()
        log.error("交易失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "org_list": org_list,
        },
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 28
0
def get_table_list(request):
    log = public.logger
    try:
        cur = connection.cursor()  # 创建游标
        sql="select table_name, table_comment from information_schema.tables " \
            "where table_schema not in ('sys', 'mysql','performance_schema','information_schema') " \
            "order by table_name asc"
        cur.execute(sql)
        rows = cur.fetchall()
        table_list = []
        for item in rows:
            tableitem = {}
            tableitem["value"] = item[0]
            tableitem["lable"] = item[0] + '  ' + item[1]
            table_list.append(tableitem)
        cur.close()
    except Exception as ex:
        log.error("获取数据表信息失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "100100", "获取数据表信息失败!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {
        "HEAD": public.resphead_setvalue(),
        "BODY": {
            "table_list": table_list
        }
    }
    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo
Exemplo n.º 29
0
def Enter(request):
    global log, fh
    operate_list_upd_flag = False  # 更新用户操作流水表标志
    # 请求流水号赋初值
    public.req_seq = 'PT_' + datetime.datetime.now().strftime(
        '%H%M%S%f') + "_" + ''.join(random.sample(
            string.digits, 6))  # 请求流水号,变量初始化一下 用户号8位+日期6位+序列号6位

    # print('根目录:', public.localhome)

    def check_user_auth():
        sql = "select  state from sys_user where user_id=%s "
        cur.execute(sql, public.user_id)
        row = cur.fetchone()
        if not row:
            public.respcode, public.respmsg = "110002", "用户不存在!"
            return False
        db_state = row[0]
        if str(db_state) != '1':
            public.respcode, public.respmsg = "110003", "用户状态异常!"
            return False
        # 校验成功。
        return True

    try:
        cur = connection.cursor()  # 创建游标

        starttime = datetime.datetime.now()
        # 获取访问路径
        if request.path[-1] == '/':
            param1 = request.path.rsplit('/')[-2]
        else:
            param1 = request.path.rsplit('/')[-1]

        # 初始化日志,根据请求的接口类别自动创建子日志
        if param1:
            log, fh = public.loger_init(param1)
        else:
            log, fh = public.loger_init('Admin_Main')

        log.info(
            '----------------------Admin_Main-begin---------------------------',
            extra={'ptlsh': public.req_seq})
        log.info("请求path:[%s]" % request.path, extra={'ptlsh': public.req_seq})
        log.info("请求method:[%s]" % request.method,
                 extra={'ptlsh': public.req_seq})
        log.info("请求GET:[%s]" % request.GET, extra={'ptlsh': public.req_seq})

        reqest_body = json.loads(
            request.body.decode(encoding='utf-8'))  # 请求报文转换为JSON报文
        if request.method != "POST":  # 仅支持POST调用
            public.respcode, public.respmsg = "100000", "api error! Support only POST!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo

        if len(str(request.body)) < maxlength:  # 日志太大不打印了,如文件上传等日志。
            req_pkg = reqest_body
            log.info("请求body:[%d][%s]" %
                     (len(str(request.body)), str(req_pkg)),
                     extra={'ptlsh': public.req_seq})
        else:
            req_pkg = '请求报文太大,不再登记到表中'  # 大的请求报文不再登记到表中

        # 获取请求变量
        public.req_ip = request.META.get('REMOTE_ADDR')  # 请求IP地址
        public.req_head = reqest_body.get('HEAD', None)  # 请求报文头
        public.req_body = reqest_body.get('BODY', None)  # 请求报文体
        if public.req_head:
            public.menu_id = public.req_head.get('mid', '')  # 菜单ID
            public.user_id = public.req_head.get('uid', None)  # 请求用户ID
            public.check_sum = public.req_head.get('checksum')  # session校验码
            public.tran_type = public.req_head['tran_type']  # 交易代码
            public.req_seq = public.req_head['req_seq']  # 请求流水号
        else:
            log.info("请求报文头错误!", extra={'ptlsh': public.req_seq})
            public.respcode, public.respmsg = "100000", "请求报文头错误!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo

        # 判断是否记录日志
        sql = "select 1 from sys_nolog_trantype where tran_type=%s"
        # log.info("判断是否记录日志:"+sql % public.tran_type, extra={'ptlsh': public.req_seq})
        cur.execute(sql, public.tran_type)
        row = cur.fetchone()
        # log.info("判断是否记录日志row:" + str(row), extra={'ptlsh': public.req_seq})
        if not row:
            try:
                sql = "INSERT INTO sys_user_operate_list(user_id,tran_type,req_ip,req_seq,req_pkg) VALUES (%s,%s,%s,%s,%s)"
                cur.execute(sql, (public.user_id, public.tran_type,
                                  public.req_ip, public.req_seq, str(req_pkg)))
                # connection.commit()  # 直接提交事务
                operate_list_upd_flag = True  # 有插入有更新,无插入不更新
            except Exception as e:
                log.error('插入用户操作日志表失败:' + str(e),
                          exc_info=True,
                          extra={'ptlsh': public.req_seq})
                public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
                )
                if 'for key' in str(e):
                    log.info("请求流水号重复![%s]" % public.req_seq,
                             extra={'ptlsh': public.req_seq})
                    public.respcode, public.respmsg = "100000", "请求流水号重复!"
                    public.respinfo = HttpResponse(public.setrespinfo())
                    return public.respinfo
                else:
                    public.respcode, public.respmsg = "100000", "插入用户操作日志表失败!"
                    public.respinfo = HttpResponse(public.setrespinfo())
                    return public.respinfo

        # 校验session
        if public.tran_type not in ['user_login_bypasswd']:
            # sesession校验
            if public.checksession(request) == False:
                public.respcode, public.respmsg = "100000", "请重新登陆!"
                public.respinfo = HttpResponse(public.setrespinfo())
                return public.respinfo
            else:
                log.info("Session校验通过", extra={'ptlsh': public.req_seq})

            # 判断用户状态,用户权限
            if not check_user_auth():
                public.respinfo = HttpResponse(public.setrespinfo())
                return public.respinfo

        # 根据请求path处理接口数据
        path = request.path.split('/')
        # 调用指定函数
        try:
            # 动态地import需要创建的类,减少报错,内存的使用,加快速度等
            cmd_import = 'from admin_app.%s import %s' % (path[2], path[3])
            # print('cmd_import=', cmd_import)
            exec(cmd_import)  # 动态地import需要创建的类
            func_main_name = '%s.Main_Proc(request)' % (path[3])
            # print('func_main_name=', func_main_name)
            log.info("----Main-[%s.Main_Proc]-start---" % (path[3]),
                     extra={'ptlsh': public.req_seq})
            public.respinfo = eval(func_main_name)
            log.info("----Main-[%s.Main_Proc]-end----" % (path[3]),
                     extra={'ptlsh': public.req_seq})
        except Exception as ex:
            log.error('程序运行错误:' + str(ex),
                      exc_info=True,
                      extra={'ptlsh': public.req_seq})
            public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
            )
            public.respcode, public.respmsg = "110001", "url error!"
            public.respinfo = HttpResponse(public.setrespinfo())

        cur.close()  # 关闭游标
        return public.respinfo
    except Exception as e:
        # print("获取错误信息:", traceback.print_exc())
        log.error('程序运行错误:' + str(e),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo
    finally:
        try:
            if not public.respinfo:  # 如果返回信息为空
                public.respcode, public.respmsg = "1000009", "系统错误[返回数据异常]"
                public.respinfo = HttpResponse(public.setrespinfo())

            resp_pkg = public.respinfo.getvalue().decode(encoding='utf-8')
            if len(str(resp_pkg)) < maxlength:  # 日志太大不打印了,如文件上传等日志。
                # print('finally3, respinfo=', public.respinfo)
                log.info("返回报文:[%d][%s]" %
                         (len(str(public.respinfo)), resp_pkg),
                         extra={'ptlsh': public.req_seq})
            else:
                resp_pkg = '返回报文太大,不记录到表中'  # 返回报文太大,不记录到表中

            if operate_list_upd_flag:
                # 获取错误堆栈中的错误信息,并格式化
                if public.exc_type and public.exc_value and public.exc_traceback:
                    errmsg = str(public.exc_type) + ' ' + str(public.exc_value)
                    for item in traceback.extract_tb(public.exc_traceback, 10):
                        # print('item=', item[0], item[1],item[2],item[3], type(item[0])) #“预处理”堆栈跟踪条目是一个4元组(文件名,行号,函数名称*,文本)
                        errmsg = errmsg + '\n' + repr(item)
                else:
                    errmsg = ''  # 未获取到错误信息
                # 更新用户操作流水表返回结果
                cur = connection.cursor()  # 创建游标
                sql = "update sys_user_operate_list set user_id=%s, resp_time=%s,resp_code=%s,resp_msg=%s,resp_pkg=%s,error_msg=%s where req_seq=%s"
                cur.execute(sql,
                            (public.user_id, datetime.datetime.now(),
                             public.respcode, public.respmsg, str(resp_pkg),
                             str(errmsg), public.req_seq))
                connection.commit()  # 直接提交事务
                cur.close()  # 关闭游标
            # connection.close() #关闭数据库

            log.info('交易处理时间: %s' % str(datetime.datetime.now() - starttime),
                     extra={'ptlsh': public.req_seq})
            log.info(
                '----------------------Admin_Main-end---------------------------',
                extra={'ptlsh': public.req_seq})

            if fh:
                fh.close()
                log.removeHandler(fh)
        except Exception as e:
            log.error('系统finally处理失败:' + str(e),
                      exc_info=True,
                      extra={'ptlsh': public.req_seq})
        return public.respinfo
Exemplo n.º 30
0
def get_crud_data(request):
    log = public.logger
    body = public.req_body

    if not public.menu_id:
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        public.respcode, public.respmsg = "100103", "配置交易上送信息有误!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    #开始处理
    try:
        # 翻页查询请求
        pagesize = int(body.get('pagesize', "10"))
        pagenum = int(body.get('pagenum', "1"))

        cur = connection.cursor()  # 创建游标
        # 根据menuid获取增删改查配置的appid
        sql = "select app_id from sys_menu where menu_id='%s' " % (
            public.menu_id)
        cur.execute(sql)
        row = cur.fetchone()
        if row:
            appid = row[0]
        else:
            public.respcode, public.respmsg = "100105", "查询菜单对应的APPID异常!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo
        if not appid:
            public.respcode, public.respmsg = "100105", "查询菜单对应的APPID异常!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo

        # 查询增删改查配置HEAD信息
        sql = "select where_ctrl, order_ctrl, table_name" \
              " from sys_crud_cfg_head where app_id=%s "
        # log.info("查询增删改查配置HEAD信息:"+sql % appid, extra={'ptlsh':public.req_seq})
        cur.execute(sql, appid)
        crud_head_row = cur.fetchone()
        if crud_head_row:
            where_ctrl = crud_head_row[0]
            order_ctrl = crud_head_row[1]
            table_name = crud_head_row[2]
        else:
            public.respcode, public.respmsg = "100115", "查询APPID异常,数据不存在!"
            public.respinfo = HttpResponse(public.setrespinfo())
            return public.respinfo

        searchinfo = body.get('searchinfo', None)
        whereinfo = ""
        # print( type(searchinfo), searchinfo )
        if searchinfo:
            # 有查询条件
            for item in searchinfo:
                selectid = item.get('selectid', None)
                selecttype = item.get('selecttype', None)
                selectvalue = item.get('selectvalue', None)

                if selectid == None or selectid == "":
                    continue
                if selecttype == None or selecttype == "":
                    continue

                # if item['uitype'] == 'datetime' and selectvalue:
                #     selectvalue = datetime.datetime.strptime(selectvalue, "%Y-%m-%d %H:%M:%S")
                if selecttype == 'like' and selectvalue:
                    selectvalue = "%" + selectvalue + "%"
                wheretemp = " and " + selectid + " " + selecttype + " '" + selectvalue + "'"
                # print(wheretemp)
                if whereinfo == "":
                    whereinfo = wheretemp
                else:
                    whereinfo = whereinfo + ' ' + wheretemp

        if where_ctrl == None:
            where_ctrl = ""
        if order_ctrl == None:
            order_ctrl = ""

        cur = connection.cursor()
        # sql = "select field_id,ui_type,search_exts from sys_crud_cfg_body " \
        #       "where state='y' and app_id=%s order by order_id asc"
        #为了使隐藏ID的也好用,所以状态不再做为条件。。
        sql = "select field_id,ui_type,search_exts from sys_crud_cfg_body " \
              "where  app_id=%s order by order_id asc"
        log.info(sql % appid, extra={'ptlsh': public.req_seq})
        cur.execute(sql, appid)
        rows = cur.fetchall()
        fieldlist = ""
        field_uitype_list = []
        field_search_list = []  # 查询配置,用于枚举转换
        for item in rows:
            if fieldlist.__len__() == 0:
                fieldlist = item[0]
            else:
                fieldlist = fieldlist + ',' + item[0]
            # 获取uitype,对multipleimage要使用list返回结果
            field_uitype_list.append(item[1])
            field_search_list.append(item[2])
            # 根据查询配置获取反回结果
        fieldlist = fieldlist.replace('data_seq_no', '1 as data_sql_no')

        if where_ctrl == None or where_ctrl == "":
            if whereinfo.__len__() > 0:
                where_ctrl = "where 1=1"
        else:
            if 'WHERE' not in where_ctrl.upper():
                where_ctrl = 'where ' + where_ctrl
            if '${USER_ID}' in where_ctrl:
                where_ctrl = where_ctrl.replace('${USER_ID}',
                                                str(public.user_id))
            if '${ORGID}' in where_ctrl:
                orgidsql = "(SELECT org_id FROM sys_user_org WHERE user_id='%s')" % public.user_id
                where_ctrl = where_ctrl.replace('${ORGID}', orgidsql)
            if '${ORG_ID}' in where_ctrl:
                orgidsql = "(SELECT org_id FROM sys_user_org WHERE user_id='%s')" % public.user_id
                where_ctrl = where_ctrl.replace('${ORG_ID}', orgidsql)

        # 获取总笔数,分页使用
        selsql = "select count(1) from " + table_name + " " + where_ctrl + " " + whereinfo + " " + order_ctrl
        log.info(selsql, extra={'ptlsh': public.req_seq})
        cur.execute(selsql)
        row = cur.fetchone()
        totalnum = row[0]

        # 分页查询
        if pagesize == 0 or not pagesize:
            pagesize = 10
        if pagenum == 0 or not pagenum:
            pagenum = 1
        startno = (pagenum - 1) * pagesize
        # endno = (pagenum) * pagesize

        selsql = "select " + fieldlist + " from " + table_name + " " + where_ctrl + " " + whereinfo + " " + order_ctrl
        selsql = selsql + " limit %s, %s" % (startno, pagesize)
        log.info(selsql, extra={'ptlsh': public.req_seq})
        cur.execute(selsql)
        rows = cur.fetchall()

        fieldlist = fieldlist.split(',')
        # print("查询时获取的表头字段:",fieldlist)
        data = {"totalnum": "0", "tabledata": []}

        data_seq_no = totalnum - (pagenum - 1) * pagesize  # 增加当前数据的序号(倒序)
        for item in rows:
            dataitem = {}
            loopid = 0
            for subitem in item:
                if subitem == None or len(str(subitem)) == 0:
                    subitem = ""
                # log.info('=mytest=='+str(fieldlist[loopid])+'-----'+str(data_seq_no)  )
                #增加一个data_sql_no序号, add by litz, 2020-10-30
                if fieldlist[loopid] == '1 as data_sql_no':  #序号列,为虚列不控制
                    dataitem['data_seq_no'] = data_seq_no
                    data_seq_no = data_seq_no - 1
                    loopid = loopid + 1
                    continue

                dataitem[fieldlist[loopid]] = subitem

                if field_search_list[
                        loopid] and field_uitype_list[loopid] != 'transfer':
                    if '${THIS}' in (
                            field_search_list[loopid]):  # 有查询配置,获取值对应的描述信息
                        if len(str(subitem)) > 0:
                            descsql = field_search_list[loopid].replace(
                                '${THIS}', '%s')
                            desccur = connection.cursor()
                            # log.info(descsql % str(subitem))
                            desccur.execute(descsql % str(subitem))
                            descrow = desccur.fetchone()
                            if descrow != None:
                                dataitem[fieldlist[loopid]] = str(
                                    subitem) + ' - ' + str(descrow[0])
                            desccur.close()

                # log.info('fieldname='+fieldlist[loopid]+',uitype='+field_uitype_list[loopid]+',value='+str(subitem) )
                if field_uitype_list[loopid] == 'multipleimage':
                    dataitem[fieldlist[loopid]] = []
                    for itemlist in str(subitem).split(';'):
                        if len(itemlist) > 0:
                            dataitem[fieldlist[loopid]].append(itemlist)
                            # 图片不存在时,显示图片不存在的默认图片
                            # if len(dataitem[fieldlist[loopid]])==0:
                            #     dataitem[fieldlist[loopid]].append(public.localurl+'static/images/irs_noimg_exists.png')

                # 循环数+1
                loopid = loopid + 1

            data['tabledata'].append(dataitem)
        cur.close()
        data['totalnum'] = totalnum
        cur.close()

    except Exception as ex:
        log.error("获取增删改查配置信息失败!" + str(ex),
                  exc_info=True,
                  extra={'ptlsh': public.req_seq})
        public.exc_type, public.exc_value, public.exc_traceback = sys.exc_info(
        )
        cur.close()
        public.respcode, public.respmsg = "100103", "数据查询失败!"
        public.respinfo = HttpResponse(public.setrespinfo())
        return public.respinfo

    public.respcode, public.respmsg = "000000", "交易成功!"
    json_data = {"HEAD": public.resphead_setvalue(), "BODY": data}

    log.info("json_data:" + str(json_data), extra={'ptlsh': public.req_seq})

    s = json.dumps(json_data, cls=public.JsonCustomEncoder, ensure_ascii=False)
    public.respinfo = HttpResponse(s)
    return public.respinfo