Пример #1
0
 def post(self):
     self.set_header("Content-Type", "text/plain")
     smscode = self.get_argument("smscode")
     phone = self.get_argument("phone")
     sendstr = 'MSG#{0}#{1}'.format(phone, smscode)
     sendMail(sendstr,sendstr)
     self.write(now())
Пример #2
0
def autoformat(entity, changes, operator, _state):
    """
    为模型自动添加创建人创建时间修改人修改时间等属性
    :param changes:
    """
    columns_ = entity.__dict__['_columns_']
    if _state == 'modified':  # 修改
        if "modifierid" in columns_:
            changes["modifierid"] = operator
        if "modifydate" in columns_:
            changes["modifydate"] = now()
    elif _state == 'added':  # 创建
        if "creatorid" in columns_:
            changes["creatorid"] = operator
        if "createdate" in columns_:
            changes["createdate"] = now()
Пример #3
0
def autoformat(entity, changes, operator, _state) :
    """
    为模型自动添加创建人创建时间修改人修改时间等属性
    :param changes:
    """
    columns_ = entity.__dict__['_columns_']
    if _state == 'modified' :  # 修改
        if "modifierid" in columns_ :
            changes["modifierid"] = operator
        if "modifydate" in columns_ :
            changes["modifydate"] = now()
    elif _state == 'added' :  # 创建
        if "creatorid" in columns_ :
            changes["creatorid"] = operator
        if "createdate" in columns_ :
            changes["createdate"] = now()
Пример #4
0
def sendlogincode(usercode=None):
    code = WechatLogic.generate_code()
    xx = Staff.query.filter(Staff.staff_id == usercode)
    xx.update({Staff.msg: code, Staff.msgexpdate: now(10)})
    db.session.commit()

    sendsmscode(user_code=usercode, code=code)
Пример #5
0
def SaveBarcode(barcodelist, message, type='input'):
    """
    将识别的二维码保存下来
    :param barcodelist:联通资产码列表
    :param type:
    :param message:
    """

    for x in barcodelist:

        uu=getUserBySource(message.source)
        if uu:
            if is_barcode_in_mission(user_code=uu,barcode=x):
            #如果此用户提交的时任务内的资产标签,那么保存下来
                pp=getPortalUser(uu)
                bb = BarcodeList(source=message.source, barcode=x,
                             type=type, msgid=message.id,
                             user_code=uu,opdate=now(),
                             topdpt=pp.topdpt)
                db.session.add(bb)
                mb=mission_barcode.query.filter(and_(mission_barcode.barcode==x,  mission_barcode.msgid==None) )
                if mb.first():
                    #只更新没有扫描到得二维码,填了msgid证明已经查过
                    mb.update({mission_barcode.msgid:message.id})

    db.session.commit()
Пример #6
0
def SaveBarcode(barcodelist, message, type='input'):
    """
    将识别的二维码保存下来
    :param barcodelist:联通资产码列表
    :param type:
    :param message:
    """

    for x in barcodelist:

        uu = getUserBySource(message.source)
        if uu:
            if is_barcode_in_mission(user_code=uu, barcode=x):
                #如果此用户提交的时任务内的资产标签,那么保存下来
                pp = getPortalUser(uu)
                bb = BarcodeList(source=message.source,
                                 barcode=x,
                                 type=type,
                                 msgid=message.id,
                                 user_code=uu,
                                 opdate=now(),
                                 topdpt=pp.topdpt)
                db.session.add(bb)
                mb = mission_barcode.query.filter(
                    and_(mission_barcode.barcode == x,
                         mission_barcode.msgid == None))
                if mb.first():
                    #只更新没有扫描到得二维码,填了msgid证明已经查过
                    mb.update({mission_barcode.msgid: message.id})

    db.session.commit()
Пример #7
0
def nextexec(frequency=None, lastexec=None):
    frequency = str(frequency)
    lastexec = lastexec if lastexec else now()

    if frequency.startswith('min:'):
        return getnextdate(lastdate=lastexec, minutes=int(frequency.split(':')[1]) * 1)
    else:
        return getnextdate(lastdate=lastexec, minutes=int(frequency.split(':')[1]) * 60)
Пример #8
0
def sendlogincode(usercode=None):
    code = WechatLogic.generate_code()
    xx = Staff.query.filter(Staff.staff_id == usercode)
    xx.update({
        Staff.msg: code,
        Staff.msgexpdate: now(10)
    })
    db.session.commit()

    sendsmscode(user_code=usercode, code=code)
Пример #9
0
def nextexec(frequency=None, lastexec=None):
    frequency = str(frequency)
    lastexec = lastexec if lastexec else now()

    if frequency.startswith('min:'):
        return getnextdate(lastdate=lastexec,
                           minutes=int(frequency.split(':')[1]) * 1)
    else:
        return getnextdate(lastdate=lastexec,
                           minutes=int(frequency.split(':')[1]) * 60)
Пример #10
0
def sendlogincode(usercode=None):
    code = WechatLogic.generate_code()
    xx = portal_user.query.filter(portal_user.user_code == usercode)
    xx.update({
        portal_user.msg: code,
        portal_user.msgexpdate:now(10)
    })
    db.session.commit()


    sendsmscode(user_code=usercode, code=code)
Пример #11
0
def before_process(x):
    """
    oracle 语句执行前
    :param x:
    :return:
    """
    thdate = now()
    nextdate = nextexec(x.frequency, thdate)
    sqlupdate = "update sqllist set nextexec='{1}',state=1,lastexec='{2}' where guid={0}"
    dbmysql().execute(sqlupdate.format(x.guid, nextdate, thdate))
    return nextdate, thdate
Пример #12
0
def get():

    sql = "select * from sqllist where state=0 and nextexec>='{0}' and nextexec<='{1}'"
    sql = sql.format(now(minutes=-1),now())
    #print(sql)
    all = dbmysql().query(sql)
    for x in all:

        #计算下次执行时间,更新状态为0:执行完成
        #更新执行时间,更新状态为1:正在执行
        thdate= now()

        nextdate = nextexec(x.frequency, thdate)
        sqlupdate = "update sqllist set  nextexec='{1}',state=1,lastexec='{2}' where guid={0}"
        dbmysql().execute(sqlupdate.format(x.guid, nextdate,thdate))
        #print(x.guid, x.sqlContent )
        #执行sql内容
        execsql(guid=x.guid, sqlContent=x.sqlContent, paras=x.paras)

        sqlupdate = "update sqllist set state=0 where guid={0}"
        dbmysql().execute(sqlupdate.format(x.guid, nextdate, thdate))
Пример #13
0
def get():

    sql = "select * from sqllist where state=0 and nextexec>='{0}' and nextexec<='{1}'"
    sql = sql.format(now(minutes=-1), now())
    #print(sql)
    all = dbmysql().query(sql)
    for x in all:

        #计算下次执行时间,更新状态为0:执行完成
        #更新执行时间,更新状态为1:正在执行
        thdate = now()

        nextdate = nextexec(x.frequency, thdate)
        sqlupdate = "update sqllist set  nextexec='{1}',state=1,lastexec='{2}' where guid={0}"
        dbmysql().execute(sqlupdate.format(x.guid, nextdate, thdate))
        #print(x.guid, x.sqlContent )
        #执行sql内容
        execsql(guid=x.guid, sqlContent=x.sqlContent, paras=x.paras)

        sqlupdate = "update sqllist set state=0 where guid={0}"
        dbmysql().execute(sqlupdate.format(x.guid, nextdate, thdate))
Пример #14
0
class ErrorMsg:
    '''
定义执行错误的类
'''

    sql = ''
    message = None
    success = True
    opdate = now()

    def __init__(self, sql=None, message=None, success=True, opdate=None):
        self.sql = sql
        self.message = message
        self.success = success
        self.opdate = opdate
Пример #15
0
def showzc(zcbh=None):
    """
    显示资产编号的详细信息
    :param zcbh:
    :return:
    """

    from mbp.models import zczb
    from  forms import BarcodeListUpdate
    from Library.datehelper import  now
    if (not zcbh ) and request.args.get('zcbh'):
        zcbh = str(request.args.get('zcbh'))
    msgid = request.args.get('msgid')

    bb = BarcodeList.query.filter(and_(BarcodeList.user_code == g.user.user_code,
                                       BarcodeList.barcode == zcbh,BarcodeList.msgid==msgid
    )
    )
    form = BarcodeListUpdate()
    # 下电标识:
    # 报废标识:未报废, 闲置-待报废, 已报废
    # 设备生命周期:在用-长期使用, 在用-两年内下线(2015年内), 在用-年内下线(2014年内), 闲置-可用, 不可用, 在用-开发测试

    form.ztbz.choices = [('未下电', '未下电'), ('已下电-已拆除', '已下电-已拆除'), ('已下电-待拆除', '已下电-待拆除')]
    form.ztbz1.choices = [('未报废', '未报废'), ('闲置-待报废', '闲置-待报废'), ('已报废', '已报废')]
    form.ztbz2.choices = [('在用-长期使用', '在用-长期使用'), ('在用-两年内下线(2015年内)', '在用-两年内下线(2015年内)'),
                          ('闲置-可用', '闲置-可用'), ('在用-开发测试', '在用-开发测试')]
    if form.validate_on_submit():
        #更新最新状态
        ztbz = form.ztbz.data
        ztbz1 = form.ztbz1.data
        ztbz2 = form.ztbz2.data
        wlwz = form.wlwz.data
        if bb:
            bb.update({BarcodeList.ztbz1: ztbz1, BarcodeList.ztbz2: ztbz2,
                       BarcodeList.ztbz: ztbz, BarcodeList.wlwz: wlwz,
                       BarcodeList.opdate:now()})

            db.session.commit()
        flash('更新成功')

    zz = zczb.query.filter(zczb.zcbqh == zcbh).first()
    child = BarcodeLogic.getChild(zcbh)

    return render_template('showzcbq.html', form=form, entry=zz, child=child, barcodeinfo=bb.first(),msgid=msgid)
Пример #16
0
def loginchk(source=None, usercode=None):
    """
    验证绑定码是否匹配
    :param source:
    :param usercode:
    :return:
    """
    from forms import WechatChkCode

    usercode = request.args.get('usercode')
    form = WechatChkCode()
    if form.validate_on_submit():
        code = form.code.data
        if usercode and code and len(code) == 4:
            x = Staff.query.filter(
                and_(Staff.staff_id == usercode, Staff.msg == code,
                     Staff.msgexpdate >= now()))

            w = x.first()
            if w:
                staff = Staff.query.filter(Staff.staff_id == usercode).first()
                if not staff:
                    flash('登录失败,查无此ID')
                    return redirect(url_for('login'))

                session["user_code"] = staff.staff_id
                session["chnl_id"] = staff.chnl_id
                remember_me = False
                if 'remember_me' in session:
                    remember_me = session['remember_me']
                    session.pop('remember_me', None)
                login_user(staff, remember=True)
                flash('登录成功')
                return redirect(url_for('index'))

            else:
                flash('验证失败,请重试')
                return redirect(url_for('login'))
        flash('验证失败,查无此ID')
        return redirect(url_for('index'))
    return render_template('checkcode.html',
                           action='loginchk',
                           opname='登录系统',
                           form=form,
                           title='请输入验证码')
Пример #17
0
def loginchk(source=None, usercode=None):
    """
    验证绑定码是否匹配
    :param source:
    :param usercode:
    :return:
    """
    from forms import WechatChkCode

    usercode = request.args.get('usercode')
    form = WechatChkCode()
    if form.validate_on_submit():
        code = form.code.data
        if usercode and code and len(code) == 4:
            x = Staff.query.filter(and_(Staff.staff_id == usercode,
                                        Staff.msg == code, Staff.msgexpdate >= now()))

            w = x.first()
            if w:
                staff = Staff.query.filter(Staff.staff_id == usercode).first()
                if not staff:
                    flash('登录失败,查无此ID')
                    return redirect(url_for('login'))

                session["user_code"] = staff.staff_id
                session["chnl_id"] = staff.chnl_id
                remember_me = False
                if 'remember_me' in session:
                    remember_me = session['remember_me']
                    session.pop('remember_me', None)
                login_user(staff, remember=True)
                flash('登录成功')
                return redirect(url_for('index'))

            else:
                flash('验证失败,请重试')
                return redirect(url_for('login'))
        flash('验证失败,查无此ID')
        return redirect(url_for('index'))
    return render_template('checkcode.html', action='loginchk', opname='登录系统', form=form, title='请输入验证码')
Пример #18
0
        phones.append(x.PHONE)
        pass
    data = {
        'senderid': senderid,
        'target': ','.join(phones),
        'content': smstmp
    }
    if phones:
        r = requests.post(url, data=data)
        print(phones, r.text)
    else:
        print('No need to send birthday sms')

    #更新发送状态,send=1,opdate=sysdate

    updatesql = 'update hy_birthsms set opdate=sysdate , send=1 where opdate is null'
    db().execute(updatesql)

    print('birth sms send over')


if __name__ == "__main__":
    print()
    while True:
        h = int(now().split(' ')[1].split(':')[0])
        if h > 8 and h < 18:
            #规定发送时间
            print(h)
            send()
            pass
        time.sleep(60 * 60 * 3)
Пример #19
0
def get():
    sql = "select * from sqllist where state=0 and nextexec>='{0}' and nextexec<='{1}'"
    sql = sql.format(now(minutes=-1), now())
    all = dbmysql().query(sql)
    for x in all:
        OracleExec(x)
Пример #20
0
def showsnlist(page=1):
    """
    开通
    申请停机
    挂失停机
    局方停机
    欠费停机
    申请销号
    高额停机
    欠费销号
    申请预销停机
    :param page:
    :return:
    """

    form = SearchForm()
    if form.validate_on_submit():
        startdate = form.startdate.data
        enddate = form.enddate.data
        t = form.t.data
        return redirect(url_for('showsnlist', s=startdate, e=enddate, t=t))

    if request.args.get('s') and request.args.get('e'):
        startdate = request.args.get('s')
        enddate = request.args.get('e')
    else:
        startdate = now(-60 * 24 * 30).split(' ')[0]
        enddate = now().split(' ')[0]
        t = request.args.get('t') if request.args.get('t') else 'list'
        return redirect(url_for('showsnlist', s=startdate, e=enddate, t=t))

    sql = "select * from DLS_SNLIST where   open_date <='{1}' and open_date >='{2}' and develop_depart_id  in ( " \
          "select chnl_id from dls_staff_chnl where staff_id='{0}') order by open_date desc"
    sql = sql.format(g.user.get_id(), enddate, startdate)
    #print(sql)
    if request.args.get('t') == "list":
        pagination = AdoHelper().paginate(page,
                                          sql=sql,
                                          per_page=POSTS_PER_PAGE)
    else:
        pagination = None
    fields = ['serial_number', 'user_state_codeset', 'open_date']
    fields_cn = ['号码', '状态', '开户时间']
    specfile = {
        '0': '<span class="label label-success">开通</span>',
        '1': '<span class="label label-warning">申请停机</span>',
        '2': '<span class="label label-warning">挂失停机</span>',
        '4': '<span class="label label-warning">局方停机</span>',
        '5': '<span class="label label-warning">欠费停机</span>',
        '6': '<span class="label label-info">申请销号</span>',
        '7': '<span class="label label-warning">高额停机</span>',
        '9': '<span class="label label-danger">欠费销号</span>',
        'F': '<span class="label label-danger">申请预销停机</span>'
    }


    sql="SELECT state_name ,count(serial_number) as count FROM `dls_snlist` where   open_date <='{1}' and open_date >='{2}' and develop_depart_id  in ( " \
        "select chnl_id from dls_staff_chnl where staff_id='{0}') group by state_name order by count desc"
    sql = sql.format(g.user.get_id(), enddate, startdate)
    #print(sql)
    if request.args.get('t') == "group":
        groupdata = AdoHelper().paginate(1, sql=sql, per_page=20000)
    else:
        groupdata = None
    gfields = ['state_name', 'count']
    gfields_cn = ['状态', '数量']
    return render_template('showsnlist.html',
                           pagination=pagination,
                           fields=fields,
                           fields_cn=fields_cn,
                           specfile=specfile,
                           form=form,
                           action='showsnlist',
                           startdate=startdate,
                           enddate=enddate,
                           groupdata=groupdata,
                           gfields=gfields,
                           gfields_cn=gfields_cn)
Пример #21
0
def execsql(guid=None, sqlContent=None, paras=None):
    #执行语句,记录错误
    errorMsglist = OracleExec(sqlContent=sqlContent,paras=paras)
    xx = [(guid, x.sql, x.success, x.message,now()) for x in errorMsglist]
    sqlresult = "insert into `sqlresult` (`sguid`,`sqlContent`,`success`,`message`,`opdate`) values (%s,%s,%s,%s,%s)"
    x = dbmysql().executemany_rowcount(sqlresult, xx)
Пример #22
0
def execsql(guid=None, sqlContent=None, paras=None):
    #执行语句,记录错误
    errorMsglist = OracleExec(sqlContent=sqlContent, paras=paras)
    xx = [(guid, x.sql, x.success, x.message, now()) for x in errorMsglist]
    sqlresult = "insert into `sqlresult` (`sguid`,`sqlContent`,`success`,`message`,`opdate`) values (%s,%s,%s,%s,%s)"
    x = dbmysql().executemany_rowcount(sqlresult, xx)
Пример #23
0
def showsnlist(page=1):
    """
    开通
    申请停机
    挂失停机
    局方停机
    欠费停机
    申请销号
    高额停机
    欠费销号
    申请预销停机
    :param page:
    :return:
    """

    form = SearchForm()
    if form.validate_on_submit():
        startdate = form.startdate.data
        enddate = form.enddate.data
        t = form.t.data
        return  redirect(url_for('showsnlist',s=startdate,e=enddate,t=t))


    if request.args.get('s') and request.args.get('e'):
        startdate= request.args.get('s')
        enddate= request.args.get('e')
    else:
        startdate = now(-60 * 24 * 30).split(' ')[0]
        enddate = now().split(' ')[0]
        t= request.args.get('t') if request.args.get('t') else 'list'
        return redirect(url_for('showsnlist', s=startdate, e=enddate,t=t))

    sql = "select * from DLS_SNLIST where   open_date <='{1}' and open_date >='{2}' and develop_depart_id  in ( " \
          "select chnl_id from dls_staff_chnl where staff_id='{0}') order by open_date desc"
    sql = sql.format(g.user.get_id(), enddate, startdate)
    #print(sql)
    if request.args.get('t') == "list":
        pagination = AdoHelper().paginate(page, sql=sql, per_page=POSTS_PER_PAGE)
    else:
        pagination=None
    fields = ['serial_number',  'user_state_codeset', 'open_date']
    fields_cn = ['号码',  '状态', '开户时间']
    specfile = {'0': '<span class="label label-success">开通</span>',
                '1': '<span class="label label-warning">申请停机</span>',
                '2': '<span class="label label-warning">挂失停机</span>',
                '4': '<span class="label label-warning">局方停机</span>',
                '5': '<span class="label label-warning">欠费停机</span>',
                '6': '<span class="label label-info">申请销号</span>',
                '7': '<span class="label label-warning">高额停机</span>',
                '9': '<span class="label label-danger">欠费销号</span>',
                'F': '<span class="label label-danger">申请预销停机</span>'
    }


    sql="SELECT state_name ,count(serial_number) as count FROM `dls_snlist` where   open_date <='{1}' and open_date >='{2}' and develop_depart_id  in ( " \
        "select chnl_id from dls_staff_chnl where staff_id='{0}') group by state_name order by count desc"
    sql = sql.format(g.user.get_id(), enddate, startdate)
    #print(sql)
    if request.args.get('t') == "group":
        groupdata=AdoHelper().paginate(1,sql=sql,per_page=20000)
    else:
        groupdata=None
    gfields = ['state_name', 'count']
    gfields_cn = ['状态', '数量']
    return render_template('showsnlist.html', pagination=pagination,
                           fields=fields, fields_cn=fields_cn,
                           specfile=specfile, form=form, action='showsnlist',
                           startdate=startdate,enddate=enddate,
                           groupdata=groupdata,gfields=gfields,gfields_cn=gfields_cn)
Пример #24
0
        print(x.PHONE)

        phones.append(x.PHONE)
        pass
    data = {'senderid': senderid,
            'target': ','.join(phones),
            'content': smstmp
    }
    if phones:
        r = requests.post(url, data=data)
        print(phones,r.text)
    else:
        print('No need to send birthday sms')

    #更新发送状态,send=1,opdate=sysdate

    updatesql = 'update hy_birthsms set opdate=sysdate , send=1 where opdate is null'
    db().execute(updatesql)

    print('birth sms send over')

if __name__ == "__main__":
    print()
    while True:
        h=int(now().split(' ')[1].split(':')[0])
        if h>8 and h<18:
            #规定发送时间
            print(h)
            send()
            pass
        time.sleep(60*60*3)