Exemplo n.º 1
0
def cel_check_length(userid, typeaccount=None):
    data = datetime.now()
    datetime(data.year, data.month, data.day - 1, 0, 0, 0)
    session = get_session()
    complete_total_specie = 0
    need_total_specie = 0

    # 已经抽检总长度
    if typeaccount == 0:
        complete_specie = session.query(PimTask).filter_by(
            user_id=userid).filter_by(work_status=3).all()
        if len(complete_specie) == 0:
            complete_total_specie = 0
        else:
            for specie in complete_specie:
                complete_total_specie += int(specie.volu_num.split('/')[1])
        return complete_total_specie
    # 需要抽检总长度
    elif typeaccount == 1:
        yes_all = session.query(PimTask).filter_by(user_id=userid).all()
        yes_complete = session.query(PimTask).filter_by(
            user_id=userid).filter_by(work_status=3).all()
        need_specie = list(set(yes_all) - set(yes_complete))
        if len(need_specie) == 0:
            need_total_specie = 0
        else:
            for specie in need_specie:
                need_total_specie += int(specie.volu_num.split('/')[1])
        return need_total_specie
Exemplo n.º 2
0
def save_input_loose():
    data = request.get_json()
    session = get_session()
    if 'user_id' in data and 'code_number' in data and 'check_color' in data \
            and 'feel' in data and 'weight' in data and 'head' in data \
            and 'middle' in data and 'tail' in data \
            and 'width_cut' in data and 'time_cut' in data:
        try:
            logger.info(data)
            loose = session.query(InputLoose).filter_by(
                code_number=data.get('code_number')).first()
            if not loose:
                input_model = InputLoose(**data)
                input_model.save(session)
                return api_result(
                    status_code=1,
                    data={'input_infoId': input_model.input_loose_id})

            else:
                loose.update(data)
                loose.save(session)
                return api_result(status_code=1,
                                  data={'input_infoId': loose.input_loose_id})

        except Exception as e:
            logger.error(e)
            session.rollback()
            raise AddLooseError
    return api_result(status_code=0, message=messages.wrong_params)
Exemplo n.º 3
0
Arquivo: api.py Projeto: jimapple/pim
def add_or_update_or_defect_info():
    '''
    # 添加,修改,删除疵点的信息
    # tyep: 0==删除,1==添加,2==修改
    '''
    request_data = request.get_json()
    try:
        session = get_session()
        if int(request_data['type']) == 1:
            del request_data['type']
            del request_data['defect_info_id']
            add_pimdefect = PimDefect(**request_data)
            add_pimdefect.save(session)
            return api_result(status_code=1,
                              data={"message": messages.status_ok})
        elif int(request_data['type']) == 0:
            add_pimdefect = session.query(PimDefect).filter_by(user_id=request_data['user_id']). \
                filter(PimDefect.defect_info_id == request_data['defect_info_id']).first()
            if add_pimdefect:
                add_pimdefect.delete(session)
                return api_result(status_code=1,
                                  data={"message": messages.status_ok})
        else:
            update_pimdefect = session.query(PimDefect).filter_by(user_id=request_data['user_id']). \
                filter(PimDefect.defect_info_id == request_data['defect_info_id']).first()
            if update_pimdefect:
                del request_data['type']
                del request_data['user_id']
                del request_data['defect_info_id']
                update_pimdefect.update(request_data)
                update_pimdefect.save(session)
                return api_result(status_code=1,
                                  data={"message": messages.status_ok})
    except Exception as e:
        logger.error(e)
Exemplo n.º 4
0
Arquivo: api.py Projeto: jimapple/pim
def check_cloth_report():
    request_data = request.get_json()
    session = get_session()
    try:
        datetimestr = request_data['datetime']
        cyli_num = request_data['cyli_num']
        datetimeformat = DateTimeFormat(datetimestr)
        datetime = datetimeformat.date2ymd2datetime()
        page_size = request_data["page_size"]
        page_index = request_data["page_index"]
        reportSQL = "select * from pim_report WHERE pim_report.user_id = '" + request_data[
            "user_id"] + "' AND pim_report.date_time BETWEEN '" + datetime[
                0] + "' AND '" + datetime[1] + "'"
        if cyli_num:
            reportSQL = "select * from pim_report WHERE pim_report.user_id = '" + request_data[
                "user_id"] + "' AND pim_report.date_time BETWEEN '" + datetime[
                    0] + "' AND '" + datetime[
                        1] + "' AND pim_report.cyli_num = '" + request_data[
                            "cyli_num"] + "'"
        if page_size == '' and page_index == '':
            page_index = 1
            page_size = 7
        reportlimit = "LIMIT %s" % (int(page_size)) + " OFFSET %s" % (
            (int(page_index) - 1)) + ";"
        test1 = session.execute(reportSQL)
        test2 = session.execute(reportSQL + reportlimit)
        total_number = len(test1.fetchall())
        querysetlist = test2.fetchall()
        total_page = math.ceil(int(total_number) / int(page_size))
        # report = PimReport.query.filter_by(user_id=request_data['user_id']). \
        #     filter(PimReport.date_time.between(datetime[0], datetime[1])).filter(PimReport.report_type == 1)
        # if cyli_num:
        #     report = report.filter(PimReport.cyli_num == cyli_num)
        # pagnator = PagenatorFlaskSqlalchemy(request_data=request_data, queryset=report)
        # querysetlist, total_number, total_page = pagnator.paging()
        if querysetlist:
            result = []
            for report in querysetlist:
                result.append({
                    'check_cloth_report_id':
                    report.report_id,
                    'check_cloth_report_pdf':
                    url_host + report.pdf_url
                })
                resp = {
                    'total_number': total_number,
                    'total_page': total_page,
                    'result': result
                }
            return api_result(status_code=1, data=resp)
        return api_result(status_code=0, message=messages.user_not_found)
    except Exception as e:
        logger.error(e)
Exemplo n.º 5
0
Arquivo: api.py Projeto: jimapple/pim
def leave_type():
    session = get_session()
    try:
        pim_leave_type = session.query(PimLeaveType).all()
        return api_result(status_code=1,
                          data={
                              "result":
                              serializer(pim_leave_type,
                                         exclude=[
                                             "user_id", "spec", "extend",
                                             "created_at", "updated_at"
                                         ])
                          })
    except Exception as e:
        logger.error(e)
Exemplo n.º 6
0
Arquivo: api.py Projeto: jimapple/pim
def save_input_info():
    request_data = request.get_json()
    try:
        session = get_session()
        if request_data["user_id"] and request_data['code_number']:
            add_saveinputinfo = session.query(PimSaveInputInfo).filter_by(user_id=request_data["user_id"]). \
                filter(PimSaveInputInfo.code_number == request_data["code_number"]).first()
            if not add_saveinputinfo:
                add_saveinputinfo = PimSaveInputInfo(**request_data)
                add_saveinputinfo.save(session)
                return api_result(
                    status_code=1,
                    data={'input_infoId': add_saveinputinfo.input_info_id})
            return api_result(status_code=0, message=messages.exist_params)
        return api_result(status_code=0, message=messages.wrong_params)
    except Exception as e:
        logger.error(e)
Exemplo n.º 7
0
Arquivo: api.py Projeto: jimapple/pim
def leaving():
    session = get_session()
    request_data = request.get_json()
    if request_data.get('leave_reason') \
            and request_data.get('start_time') and request_data.get('end_time') \
            and request_data.get('work_hand_id') and request_data.get('receiver_id') \
            and request_data.get('leave_type_id') and request_data.get('user_id'):
        # logger.info(PimLeaveWorkHandType.query.all()[0].work_hang_type_id)
        # print(PimLeaveReceiver.query.all()[0].leave_receiver_id)
        # print(PimLeaveType.query.all()[0].leave_type_id)
        try:
            leave = PimLeave(**request_data)
            leave.save(session)
            return api_result(status_code=1, data={"message": "ok"})
        except Exception as e:
            logger.error(e)
            session.rollback()
            raise LeavingError("请假参数错误!")
    else:
        return api_result(status_code=0, data={"message": "failed"})
Exemplo n.º 8
0
def yesterday_complete_species(userid, typeaccount=None):
    data = datetime.now()
    datetime(data.year, data.month, data.day - 1, 0, 0, 0)
    session = get_session()
    count = None

    if typeaccount == 0:
        count = session.query(PimTask).filter_by(user_id=userid).filter_by(
            work_status=3).filter(
                PimTask.updated_at.between(
                    datetime(data.year, data.month, data.day - 1, 0, 0, 0),
                    datetime(data.year, data.month, data.day, 0, 0,
                             0))).count()

    elif typeaccount == 1:
        all_count = session.query(PimTask).filter_by(user_id=userid).count()
        yes_count_before = session.query(PimTask).filter_by(
            user_id=userid).filter_by(work_status=3).filter(
                PimTask.updated_at < datetime(data.year, data.month, data.day -
                                              1, 0, 0, 0)).count()

        count = all_count - yes_count_before
    return count