예제 #1
0
def emp_type_change(dt, max_dt=None):
    d = {}
    try:
        m = MsgType.objects.get(id=4)  # 消息类别
    except:
        return None

    begin_date = datetime_offset_month(dt, -3)  # 开始时间
    end_date = begin_date + datetime.timedelta(
        days=m.msg_ahead_remind, hours=23, minutes=59, seconds=59)
    d["Hiredday__gte"] = begin_date
    d["Hiredday__lte"] = end_date
    qs = Employee.objects.filter(**d)
    for emp in qs:
        msg = InstantMsg()
        msg.content = ""
        if emp.PIN:
            msg.content += u"%s" % _(u"员工工号") + emp.PIN + ";"
        if emp.EName:
            msg.content += u"%s" % _(u"员工姓名") + emp.EName + ";"
        if len(msg.content) != 0:
            if (begin_date.year == emp.Hiredday.year) and (
                    begin_date.month
                    == emp.Hiredday.month) and (begin_date.day
                                                == emp.Hiredday.day):
                msg.content += datetime.datetime.now().strftime(
                    "%Y-%m-%d") + u" %s" % _(u"转正!")
            else:
                msg.content += datetime_offset_month(
                    emp.Hiredday, 3).strftime("%Y-%m-%d") + u" %s" % _(u"转正!")
            msg.monitor_last_time = datetime.datetime.now()
            msg.msgtype = MsgType.objects.get(pk=4)  # 写在BaseCode表中消息类型,6代表人事信息
            msg.save()
예제 #2
0
def emp_type_change(dt,max_dt=None):
    from mysite.worktable.models import MsgType
    from mysite.personnel.models import Employee
    d={}
    try:
        m=MsgType.objects.get(id=4)#消息类别
    except:
        return None
    
    begin_date=datetime_offset_month(dt,-3)#开始时间
    end_date=begin_date+datetime.timedelta(days=m.msg_ahead_remind,hours=23,minutes=59,seconds=59)
    d["Hiredday__gte"]=begin_date
    d["Hiredday__lte"]=end_date
    qs=Employee.objects.filter(**d)
    for emp in qs:
        msg=InstantMsg()
        msg.content=""
        if emp.PIN:
            msg.content+=u"%s"%_(u"员工工号")+emp.PIN+";"
        if emp.EName:
            msg.content+=u"%s"%_(u"员工姓名")+emp.EName+";"
        if len(msg.content)!=0:
            if (begin_date.year==emp.Hiredday.year) and (begin_date.month==emp.Hiredday.month) and (begin_date.day==emp.Hiredday.day):
                msg.content+=u"%s"%_(u'今天转正!')
            else:
                msg.content+=datetime_offset_month(emp.Hiredday,3).strftime("%Y-%m-%d")+u"%s"%_(u"转正!")
            msg.monitor_last_time=datetime.datetime.now()
            msg.msgtype=MsgType.objects.get(pk=4)#写在BaseCode表中消息类型,6代表人事信息
            msg.save()
예제 #3
0
def birthday_msg(dt, max_dt=None):
    from mysite.personnel.models import Employee
    from mysite.worktable.models import MsgType
    from django.db.models import Q
    d = {}
    #如果今天已经扫描过,那就扫描最后一次扫描到现在这个时段进来的人的生日
    #if max_dt['monitor_last_time__max']:
    # d["create_time__gt"]=max_dt['monitor_last_time__max']
    try:
        m = MsgType.objects.get(id=4)  #消息类别
    except:
        return None

    begin_date = dt  #开始时间
    end_date = dt + datetime.timedelta(days=m.msg_ahead_remind)  #结束时间

    days = m.msg_ahead_remind
    in_dates = []
    for i in range(0, days + 1):
        tmp_date = begin_date + datetime.timedelta(days=i)
        if tmp_date <= end_date:
            in_dates.append([tmp_date.month, tmp_date.day])

    query = "|".join([
        "(Q(Birthday__month=%s)&Q(Birthday__day=%s))" % (m, dd)
        for m, dd in in_dates
    ])
    qs = []
    if query:
        qs = Employee.objects.filter(**d).filter(eval(query))

    for emp in qs:
        msg = InstantMsg()
        msg.content = ""
        if emp.PIN:
            msg.content += u"%s" % _(u"员工工号") + emp.PIN + ";"
        if emp.EName:
            msg.content += u"%s" % _(u"员工姓名") + getattr(emp, "EName") + ";"
        if len(msg.content) != 0:
            if emp.Birthday.month == dt.month and emp.Birthday.day == dt.day:
                msg.content += datetime.datetime.now().strftime(
                    "%Y-%m-%d") + u" %s" % _(u"过生日!")
            else:
                msg.content += str(dt.year) + "-" + str(
                    emp.Birthday.month) + "-" + str(
                        emp.Birthday.day) + u" %s" % _(u"过生日!")
            msg.monitor_last_time = datetime.datetime.now()
            msg.msgtype = MsgType.objects.get(pk=4)  #人事公告id=4
            msg.save()
예제 #4
0
def pos_cartype_change():
    from mysite.worktable.models import MsgType
    from mysite.personnel.models.model_iccard import ICcard
    from mysite.personnel.models.model_issuecard import IssueCard, CARD_OVERDUE, CARD_VALID, POS_CARD
    from django.db import models, connection
    from django.core.cache import cache
    from base.cached_model import cache_key
    if get_option("POS_ID"):
        objcard = IssueCard.objects.filter(cardstatus=CARD_VALID,
                                           card_privage=POS_CARD)
    else:
        objcard = IssueCard.objects.filter(cardstatus__in=CARD_VALID,
                                           card_privage=POS_CARD,
                                           sys_card_no__isnull=False)
    if objcard:
        for obj in objcard:
            if (obj.type is not None):
                nowtime = datetime.datetime.now().date()
                objiccard = ICcard.objects.filter(pk=obj.type_id)
                if objiccard:
                    if type(obj.issuedate) == type(datetime.datetime.now()):
                        iscardate = obj.issuedate.date()
                    else:
                        iscardate = obj.issuedate
                    daycount = (nowtime - iscardate).days
                    maxday = objiccard[0].use_date
                    if (daycount > maxday and maxday > 0):  #卡是否过期
                        obj.cardstatus = CARD_OVERDUE  #修改卡状态为过期
                        if get_option("POS_ID"):
                            obj.save(force_update=True, log_msg=False)
                        else:
                            models.Model.save(obj, force_update=True)
                            key = cache_key(obj, obj.pk)
                            cache.delete(key)

                        msg = InstantMsg()
                        msg.content = ""
                        if obj.UserID.PIN:
                            msg.content += u"%s" % _(
                                u"员工工号") + obj.UserID.PIN + ";"
                        if obj.UserID.EName:
                            msg.content += u"%s" % _(
                                u"员工姓名") + obj.UserID.EName + ";"
                        if len(msg.content) != 0:
                            msg.content += u"%s" % _(u"消费卡过期!")
                            msg.monitor_last_time = datetime.datetime.now()
                            msg.msgtype = MsgType.objects.get(
                                pk=5)  #写在BaseCode表中消息类型,10代表消费信息
                            msg.save()
예제 #5
0
def birthday_msg(dt,max_dt=None):
    from mysite.personnel.models import Employee
    from mysite.worktable.models import MsgType
    from django.db.models import Q
    d={}
    #如果今天已经扫描过,那就扫描最后一次扫描到现在这个时段进来的人的生日
    #if max_dt['monitor_last_time__max']:
       # d["create_time__gt"]=max_dt['monitor_last_time__max']
    try:
        m=MsgType.objects.get(id=4)#消息类别
    except:
        return None
    
    begin_date=dt#开始时间
    end_date=dt+datetime.timedelta(days=m.msg_ahead_remind)#结束时间
    
    days=m.msg_ahead_remind
    in_dates=[]
    for i in range(0,days+1):
        tmp_date=begin_date+datetime.timedelta(days=i)
        if tmp_date<=end_date:
            in_dates.append([tmp_date.month,tmp_date.day])
            
    query="|".join(["(Q(Birthday__month=%s)&Q(Birthday__day=%s))"%(m,dd) for m,dd in in_dates])
    qs=[]
    if query:
        qs=Employee.objects.filter(**d).filter(eval(query))
        
    for emp in qs:
        msg=InstantMsg();
        msg.content=""
        if emp.PIN:
            msg.content+=u"%s"%_(u"员工工号")+emp.PIN+";"
        if emp.EName:
            msg.content+=u"%s"%_(u"员工姓名")+getattr(emp,"EName")+";"
        if len(msg.content)!=0:
            if emp.Birthday.month==dt.month and emp.Birthday.day==dt.day:
                msg.content+=u"%s"%_(u'今天过生日!')
            else:
                msg.content+=str(dt.year)+"-"+str(emp.Birthday.month)+"-"+str(emp.Birthday.day)+u"%s"%_(u"过生日!")
            msg.monitor_last_time=datetime.datetime.now()
            msg.msgtype=MsgType.objects.get(pk=4)#人事公告id=4
            msg.save()