def registerSuper(user_name, user_pass, status):
    '''
    注册管理员
    :param user_name: 用户name
    :param user_pass: 用户密码
    :param status: 用户级别
    :return:
    '''
    strList = []
    strList.append(user_name)
    strList.append(user_pass)
    if strUtils.isLegals(strList) == False:
        message = "账号、密码、不能为空、含有空字符"
    else:
        try:
            user = User(user=user_name,
                        pw=MD5utils.getMD5(user_pass),
                        status=status,
                        department_id=-1)
            db.session.add(user)
            db.session.commit()
            message = STR_SUCCESS
        except Exception as e:
            systemlog.log_error(e)
            message = STR_ERROR
    return message
def save_ic_table(table_id, jsonObj):
    '''
    保存bom列表
    :param table_id:bom表id
    :param jsonObj:bom表json数据
    :return:操作结果
    '''
    ret_message = STR_ERROR
    item_id = None
    try:
        #根据bom_id查询bom
        itemTable = ItemTable.query.get(int(table_id))
    except Exception as e:
        systemlog.log_error(e)
        itemTable = None
    if itemTable:  #bom表存在则先全部删除
        item_id = itemTable.id
        if delete_item_table(itemTable.id) == False:
            return ret_message, None
    itemTable = ItemTable(project_id=jsonObj['project_id'],
                          file_name=jsonObj['file_name'],
                          file_id=jsonObj['file_id'],
                          item_num=jsonObj['item_num'],
                          version=jsonObj['version'],
                          user_id=current_user.id,
                          auditing=jsonObj['auditing'],
                          proofreading=jsonObj['proofreading'],
                          approval=jsonObj['approval'],
                          signer=jsonObj['signer'],
                          date=jsonObj['date'])
    if item_id:
        itemTable.id = item_id
    try:  #进行添加
        db.session.add(itemTable)
        db.session.commit()
        items = []
        for item in jsonObj['items']:
            it = ItemDetail(index=item['index'],
                            item_number=item['item_number'],
                            name=item['name'],
                            model=item['model'],
                            note=item['note'],
                            install_number=item['install_number'],
                            unit=item['unit'],
                            number=item['number'],
                            remark=item['remark'],
                            ic_item_header_id=itemTable.id)
            items.append(it)
        db.session.add_all(items)
        db.session.commit()
        ret_message = STR_SUCCESS
    except Exception as e:  #出现异常全部滚回
        systemlog.log_error(e)
        if itemTable:
            delete_item_table(itemTable.id)
    if itemTable:
        bom_id = itemTable.id
    else:
        bom_id = None
    return ret_message, bom_id
Beispiel #3
0
def up_company(company_id,name,company_logo_file,jindee_id):
    '''
    更新公司
    :param company_id: 公司id
    :param name: 新名称
    :param company_logo_file: 新公司logo文件
    :param jindee_id: 新金蝶配置id
    :return:
    '''
    message=STR_ERROR
    if strUtils.isLegal(name) is False:
        message = "名称不能空,或含有空格"
        return message
    try:
        company = Company.query.get(int(company_id))
        if company:
            company.name = name
            if jindee_id:
                company.jindee_id = jindee_id
            if company_logo_file:
                logo_name = MD5utils.getMD5(company_logo_file.filename + name) + '.' + \
                            company_logo_file.content_type.split('/')[-1]
                company.logo_file = logo_name
                company_logo_file.save(setting.company_log_path + logo_name)
            db.session.commit()
            message = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)
        pass
    return message
Beispiel #4
0
def add(project_id, project_name, department_id, u_id):
    '''
    添加项目
    :param project_id: 项目id
    :param project_name: 项目名称
    :param department_id: 部门id
    :param u_id: 负责人id
    :return:
    '''
    data = {}
    if strUtils.isLegals([project_id, department_id, u_id]) == False:
        data['message'] = "项目id不能含有空格或为空!"
        data['reurl'] = ''
    else:
        try:
            project = Project(id=project_id,
                              name=project_name,
                              department_id=department_id,
                              super_user_id=u_id)
            db.session.add(project)
            db.session.commit()
            data['message'] = STR_SUCCESS
            data['reurl'] = "/admin/project?project_id=" + project_id
        except Exception as e:
            systemlog.log_error(e)
            data['reurl'] = ''
            data['message'] = STR_ERROR
    return data
Beispiel #5
0
def add_company(name,company_logo_file,jindee_id):
    '''
    添加公司
    :param name: 公司名称
    :param company_logo_file:logo文件
    :param jindee_id: 金蝶配置id
    :return:
    '''
    message=""
    if strUtils.isLegal(name) is False:
        message = "名称不能空,或含有空格"
        return message
    try:
        #将logo文件名+公司名字 取md5形成新的文件名
        logo_name = MD5utils.getMD5(company_logo_file.filename+name)+'.'+company_logo_file.content_type.split('/')[-1]
        company = Company(name=name,logo_file = logo_name,jindee_id=jindee_id)
        if company_logo_file:
            company_logo_file.save(setting.company_log_path+logo_name)
        db.session.add(company)
        db.session.commit()
        message = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)
        message = STR_ERROR
    return message
Beispiel #6
0
def updata(project_id,date,worktime):
    '''
    更新工时
    :param project_id: 项目id
    :param date: 日期
    :param worktime: 工时
    :return:
    '''
    now_time = timeUtils.getTime("%Y-%m-%d")
    work_hours = WorkHour.query.filter(WorkHour.project_id == project_id, WorkHour.user_id == current_user.id,
                                       WorkHour.date == date).first()
    if work_hours:
        work_hours.worktime = worktime
        work_hours.time = now_time
        work_hours.status = 1
    else:
        work_hours = WorkHour(user_id=current_user.id, project_id=project_id, worktime=worktime, time=now_time,
                              date=date)
        db.session.add(work_hours)
    try:
        db.session.commit()
        ret = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)
        systemlog.log_error("提交工时出错")
        ret = "提交失败,请检查提交内容并重试"
    return ret
def register(user_name, user_pass, department_id, company_id, status):
    '''
    用户注册
    :param user_name: 用户名称
    :param user_pass: 用户密码
    :param department_id: 用户部门
    :param company_id: 用户公司
    :param status: 用户状态
    :return:
    '''
    strList = []
    strList.append(user_name)
    strList.append(user_pass)
    if int(status) < 10:
        if int(department_id) < 0:
            message = "注册失败,请选择部门!"
            return message
    if strUtils.isLegals(strList) == False:
        message = "账号、密码、不能为空、含有空字符"
    else:
        try:
            user = User(user=user_name,
                        pw=MD5utils.getMD5(user_pass),
                        department_id=department_id,
                        company_id=company_id,
                        status=status)
            db.session.add(user)
            db.session.commit()
            message = STR_SUCCESS
        except Exception as e:
            systemlog.log_error(e)
            message = STR_ERROR
    return message
def is_init():
    '''
    系统是否初始化
    :return:
    '''
    isTrue = False
    try:
        user = User.query.filter().first()
        if user:
            isTrue = True
    except Exception as e:
        systemlog.log_error(e)
    return isTrue
def delete_jindee(jindee_id):
    '''
    删除金蝶配置
    :param jindee_id: 金蝶配置id
    :return:
    '''
    try:
        jindee = Jindee.query.get(int(jindee_id))
        db.session.delete(jindee)
        db.session.commit()
        message = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)
        message = STR_ERROR
    return message
Beispiel #10
0
def deleteByID(work_id):
    '''
    根据id删除工时
    :param work_id: 工时id
    :return:
    '''
    work_hours = WorkHour.query.filter(WorkHour.id == work_id).first()
    try:
        db.session.delete(work_hours)
        db.session.commit()
        mess = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)
        mess = STR_ERROR
    return mess
Beispiel #11
0
def delete_company(company_id):
    '''
    删除公司
    :param company_id: 公司id
    :return:
    '''
    try:
        company = Company.query.get(int(company_id))
        db.session.delete(company)
        db.session.commit()
        message = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)
        message = STR_ERROR
    return message
Beispiel #12
0
def addproject():
    '''
    添加项目api
    :return:
    '''
    result = request.form
    try:
        project_id = result['project_id']
        project_name = result['project_name']
        department_id = result['department_id']
        u_id = result['user_id']
    except Exception as e:
        systemlog.log_error(e)
        return render_template('alert.html', message="提交参数错误")
    data = projectService.add(project_id, project_name, department_id, u_id)
    return render_template('alert.html', message=data['message'],reurl=data['reurl'])
Beispiel #13
0
def up_user_status(user_id, status):
    '''
    更新用户状态
    :param user_id: 用户id
    :param status: 用户状态
    :return:
    '''
    try:
        user = User.query.get(int(user_id))
        user.status = status
        db.session.commit()
        message = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)
        message = STR_ERROR
    return message
Beispiel #14
0
def delete(project_id):
    '''
    删除项目
    :param project_id: 项目id
    :return:
    '''
    try:
        project = Project.query.get(project_id)
        print(project)
        db.session.delete(project)
        db.session.commit()
        message = STR_SUCCESS
    except Exception as e:
        print(1111)
        systemlog.log_error(e)
        message = STR_ERROR
    return message
def copy_ic_table(jsonObj):
    '''
    复制bom表
    :param jsonObj: bomjson数据
    :return:
    '''
    ret_message = STR_ERROR
    itemTable = ItemTable(project_id=jsonObj['project_id'],
                          file_name=jsonObj['file_name'],
                          file_id=jsonObj['file_id'],
                          item_num=jsonObj['item_num'],
                          version=jsonObj['version'],
                          user_id=current_user.id,
                          auditing=jsonObj['auditing'],
                          proofreading=jsonObj['proofreading'],
                          approval=jsonObj['approval'],
                          signer=jsonObj['signer'],
                          date=jsonObj['date'])
    try:  #进行添加
        db.session.add(itemTable)
        db.session.commit()
        items = []
        for item in jsonObj['items']:
            it = ItemDetail(index=item['index'],
                            item_number=item['item_number'],
                            name=item['name'],
                            model=item['model'],
                            note=item['note'],
                            install_number=item['install_number'],
                            unit=item['unit'],
                            number=item['number'],
                            remark=item['remark'],
                            ic_item_header_id=itemTable.id)
            items.append(it)
        db.session.add_all(items)
        db.session.commit()
        ret_message = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)  #出现异常全部滚回
        if itemTable.id:
            delete_item_table(itemTable.id)
    if itemTable.id:
        bom_id = itemTable.id
    else:
        bom_id = None
    return ret_message, bom_id
Beispiel #16
0
def add_project_user(project_id, users):
    '''
    添加项目用户
    :param project_id: 项目id
    :param users: 用户id列表
    :return:
    '''
    try:
        project = Project.query.get(project_id)
        for u_id in users:
            user = User.query.get(int(u_id))
            project.users.append(user)
        db.session.commit()
        message = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)
        message = STR_ERROR
    return message
Beispiel #17
0
def init_db():
    '''
    初始化数据库
    :return:
    '''
    try:
        User.query.filter().first()
    except sqlalchemy.exc.OperationalError:
        systemlog.log_info("未发现数据库...\n")
        systemlog.log_info("准备初始化数据库...\n")
        db.session.execute("PRAGMA foreign_keys = OFF;")
        for sql in sql_List:
            try:
                db.session.execute(sql)
                db.session.commit()
            except Exception as e:
                systemlog.log_error(e)
        systemlog.log_info("数据库初始化完成...")
Beispiel #18
0
def delete(department_id):
    '''
    删除部门
    :param department_id: 部门id
    :return:
    '''
    if strUtils.isLegals([department_id]) == False:
        message = '部门id不能为空'
    else:
        try:
            department = Department.query.get(int(department_id))
            db.session.delete(department)
            db.session.commit()
            message = STR_SUCCESS
        except Exception as e:
            systemlog.log_error(e)
            message = STR_ERROR
    return message
Beispiel #19
0
def delete(user_id):
    '''
    删除用户
    :param user_id: 用户id
    :return:
    '''
    if user_id == None or user_id == "":
        message = '用户id不能为空'
    else:
        try:
            user = User.query.get(int(user_id))
            print(user)
            db.session.delete(user)
            db.session.commit()
            message = STR_SUCCESS
        except Exception as e:
            systemlog.log_error(e)
            message = STR_ERROR
    return message
Beispiel #20
0
def get_department():
    '''
    获取部门列表
    :return:
    '''
    data = {}
    isTrue = False
    result = request.form
    try:
        company_id = result['company_id']
    except Exception as e:
        systemlog.log_error(e)
        data['message'] = "公司id错误"
        data['status'] = isTrue
        return json.dumps(data)
    data['departments'] = departmentService.get_department_by_company(
        company_id)
    data['status'] = True
    return json.dumps(data)
Beispiel #21
0
def get_jiari():
    '''
    获取节假日api(根据三方api 以弃用)
    :return:
    '''
    result = request.form
    ret_data = {}
    isTrue = False
    try:
        #company_id = result['company_id']
        #type = result['type']
        days = result['days']
    except Exception as e:
        systemlog.log_error(e)
        ret_data['message'] = "参数错误!"
        ret_data['status'] = isTrue
        return json.dumps(ret_data)
    ret_data = timeUtils.getWeekend(days)
    return ret_data
Beispiel #22
0
def up_project_name(project_id, new_name):
    '''
    更新项目名称
    :param project_id: 项目id
    :param new_name: 新项目名称
    :return:
    '''
    if project_id == None or project_id == "" or new_name == None or new_name == "":
        message = "参数有误!"
    else:
        try:
            project = Project.query.get(project_id)
            project.name = new_name
            db.session.commit()
            message = STR_SUCCESS
        except Exception as e:
            systemlog.log_error(e)
            message = STR_ERROR
    return message
Beispiel #23
0
def up_user_department(department_id, user_id):
    '''
    跟新用户部门
    :param department_id:
    :param user_id:
    :return:
    '''
    message = STR_ERROR
    try:
        department = Department.query.get(int(department_id))
        if department:
            user = User.query.get(int(user_id))
            if user:
                user.department_id = department_id
                db.session.commit()
                message = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)
    return message
Beispiel #24
0
def delete(project_id,date,u_id):
    '''
    删除工时
    :param project_id: 项目id
    :param date: 日期
    :param u_id: 用户id
    :return:
    '''
    work_hours = WorkHour.query.filter(WorkHour.project_id == project_id,WorkHour.date ==date , WorkHour.user_id ==u_id).first()
    try:
        if not work_hours:
            raise Exception('没有找到该工时:uid:'+u_id+" pid:"+project_id+" date:"+date)
        work_hours.status = -1
        db.session.commit()
        mess = STR_SUCCESS
    except Exception as e:
        systemlog.log_error(e)
        mess = STR_ERROR
    return mess
def delete_item_table(table_id):
    '''
    删除bom表
    :param table_id: bom表id
    :return:
    '''
    isTrue = False
    try:
        itemTable = ItemTable.query.get(int(table_id))
        sql = 'DELETE FROM ' + ItemDetail.__tablename__ + ' WHERE  ic_item_header_id = ' + str(
            itemTable.id)
        db.session.execute(sql)
        db.session.commit()
        db.session.delete(itemTable)
        db.session.commit()
        isTrue = True
    except Exception as e:
        systemlog.log_error(e)
    return isTrue
Beispiel #26
0
def up_department_name(department_id,new_name):
    '''
    更新部门名称
    :param department_id: 部门id
    :param new_name: 新名称
    :return:
    '''
    if strUtils.isLegals([department_id,new_name]) == False:
        message = '不能为空或含有空格'
    else:
        try:
            department = Department.query.get(int(department_id))
            department.name=new_name
            db.session.commit()
            message = STR_SUCCESS
        except Exception as e:
            systemlog.log_error(e)
            message = STR_ERROR
    return message
Beispiel #27
0
def up_project_status(project_id, type):
    '''
    更新项目状态
    :param project_id: 项目id
    :param type: 项目状态
    :return:
    '''
    if project_id == None or project_id == "" or type == None or type == "":
        message = '参数有误'
    else:
        try:
            project = Project.query.get(project_id)
            project.status = int(type)
            db.session.commit()
            message = STR_SUCCESS
        except Exception as e:
            systemlog.log_error(e)
            message = STR_ERROR
    return message
Beispiel #28
0
def add(name,company_id):
    '''
    添加部门
    :param name: 部门名称
    :param company_id: 公司id
    :return:
    '''
    if strUtils.isLegals([name]) == False:
        message = '部门名称不能为空'
    else:
        try:

            department =  Department(name=name,company_id =company_id)
            db.session.add(department)
            db.session.commit()
            message = STR_SUCCESS
        except Exception as e:
            systemlog.log_error(e)
            message = STR_ERROR
    return message
def like_ICItem(data, types, like=True):
    '''
    根据类型模糊搜索物料
    :param data: 模糊检索数据
    :param types: 类型
    :return: 所有检索结果集
    '''
    dbpool = DbPoolUtil.get_dbpool(str(current_user.get_company().jindee_id))
    if not dbpool:
        systemlog.log_error(current_user.department.company.name + ":未找到金蝶数据库")
        return []
    if like:
        rows = jindeeDao.like_ICItem(dbpool, data, types)
    else:
        rows = jindeeDao.select_ICItem(dbpool, data, types)
    ret_list = rows if type(rows) == list else []
    for row in ret_list:
        if not row['FQty'] == None:
            row['FQty'] = float(row['FQty'])
    return ret_list
Beispiel #30
0
def select_icitem():
    '''
    根据类型搜索物料
    :return:
    '''
    ret_data = {}
    isTrue = False
    result = request.form
    try:
        #company_id = result['company_id']
        type = result['type']
        data = result['data']
    except Exception as e:
        systemlog.log_error(e)
        ret_data['message'] = "参数错误!"
        ret_data['status'] = isTrue
        return json.dumps(ret_data)
    ret_data['items'] = jindeeService.like_ICItem(data, type)
    ret_data['status'] = True
    return json.dumps(ret_data)