Beispiel #1
0
def add_staff():
    if request.method == "POST":
        # name,property_id,role=12
        # create_time,update_time解决方案
        data = request.get_json()
        name = data["name"]
        property_id = data["property_id"]
        db_conn = get_mysql_db()
        err = None

        if (db_conn.execute("SELECT id FROM mvp.t_member WHERE name = ? and is_delete=0", (name,)).fetchone()
                is not None
        ):
            err = "User {0} is already registered.".format(name)

        if err is None:
            db_conn.execute(
                "INSERT INTO mvp.t_member (name, password, role, property_id) VALUES (%s, %s, %s, %s)",
                (name, generate_password_hash("123456"), 12, property_id),
            )

            return jsonify(code=ReturnCode.SUCCESS.value, msg="")

        # flash(err)
        return jsonify(code=ReturnCode.FAIL.value, msg=err)
Beispiel #2
0
def mem_modify_pwd():
    if request.method == "POST":
        data = request.get_json()
        mem_id = data["id"]
        pwd = data["password"]
        new_pwd = data["new_password"]
        db_conn = get_mysql_db()

        err = None

        mem = db_conn.execute(
            "SELECT id FROM mvp.t_member WHERE id = ? AND password = ?  and is_delete=0",
            (mem_id, generate_password_hash(pwd),)
        ).fetchone()

        if mem:
            try:
                db_conn.execute("UPDATE mvp.t_member SET password = ? WHERE id = ?",
                                (generate_password_hash(new_pwd), mem_id),)
                db_conn.commit()
            except Exception as e:
                err = str(e)
        else:
            err = "密码错误"
        if not err:
            return jsonify(code=ReturnCode.SUCCESS.value)

        return jsonify(code=ReturnCode.FAIL.value, msg=err)
Beispiel #3
0
def get_community_info_func(community_id):
    db_conn = get_mysql_db()
    cmnt = db_conn.execute(
        "SELECT id as community_id,community_name,property_id,status,"
        " address,contact_name,contact_number,create_time"
        " FROM mvp.t_community_base "
        " WHERE id=? and is_delete=0",
        (community_id,)
    ).fetchone()
    cmnt = serialize_row(cmnt)
    return cmnt
Beispiel #4
0
def community_list():
    if request.method == "POST":
        req_data = request.get_json()
        ppt_id = req_data["property_id"]

        db_conn = get_mysql_db()
        cmnts = db_conn.execute(
            "SELECT id as community_id, community_name, status, address, create_time"
            " FROM mvp.t_community_base "
            " WHERE property_id=?  and is_delete=0"
            " ORDER BY id ASC",
            (ppt_id,)
        ).fetchall()

        cmnts = serialize_row(cmnts)

        return jsonify(code=ReturnCode.SUCCESS.value,
                       data=cmnts)
Beispiel #5
0
def add_community_building():
    if request.method == "POST":
        req_data = request.get_json()
        cmnt_id = req_data["community_id"]
        operatior = req_data["member_id"]
        bds = req_data["building"]

        cmnt = get_community_info_func(cmnt_id)
        cmnt_name = cmnt["community_name"]

        db_conn = get_mysql_db()
        db_session_class = sessionmaker(bind=db_conn)
        db_session = db_session_class()

        err = None

        try:
            to_db_data = []
            if isinstance(bds, list):
                for bd in bds:
                    to_db_data.append(
                        {"building_no": bd["building_no"],
                         "building_name": bd["building_name"],
                         "community_id": cmnt_id,
                         "community_name": cmnt_name,
                         "floor_size": bd.get("floor_size"),
                         "create_operator": operatior}
                    )
            db_session.execute(
                "INSERT INTO t_community_building "
                " (building_no,building_name,community_id,community_name,floor_size,create_operator)"
                " VALUES (:building_no,:building_name,:community_id,:community_name,:floor_size,:create_operator)",
                to_db_data
            )
            db_session.commit()
        except Exception as ex:
            err = str(ex)
            db_session.rollback()

        db_session.close()
        if err:
            return jsonify(code=ReturnCode.FAIL.value, msg=err)

    return jsonify(code=ReturnCode.SUCCESS.value, msg="")
Beispiel #6
0
def mem_list():
    if request.method == "POST":
        req_data = request.get_json()
        ppt_id = req_data["property_id"]
        # mem_id = req_data["id"]
        db_conn = get_mysql_db()
        # ppt_id = db_conn.execute(
        #     "SELECT property_id FROM mvp.t_member WHERE id=? and is_delete=0",
        #     (mem_id,)
        # ).fetchone()[0]
        mems = db_conn.execute(
            "SELECT id, name, nick_name, role, create_time"
            " FROM mvp.t_member "
            " WHERE property_id=?  and is_delete=0"
            " ORDER BY id ASC",
            (ppt_id,)
        ).fetchall()

        mems = serialize_row(mems)

        return jsonify(code=ReturnCode.SUCCESS.value,
                       data={"member": mems})
Beispiel #7
0
def login():
    if request.method == "POST":
        data = request.get_json()
        name = data["name"]
        pwd = data["password"]
        db_conn = get_mysql_db()
        err = None

        mem = db_conn.execute(
            "SELECT id FROM mvp.t_member WHERE name = ? and is_delete=0", (name,)
        ).fetchone()
        if not mem:
            err = f"{name} is not registered."
        elif not check_password_hash(mem["password"], pwd):
            err = "Incorrect password"
        elif mem["role"] == 99:
            err = f"{name} has not permission"
        if err is None:
            return jsonify(code=ReturnCode.SUCCESS.value,
                           data={"token": token.create_token(mem["id"], "member")})
        # flash(err)
        return jsonify(code=ReturnCode.FAIL.value, msg=err)
Beispiel #8
0
def add_community():
    if request.method == "POST":
        req_data = request.get_json()
        ppt_id = req_data["property_id"]
        cmnt_name = req_data["community_name"]
        contact_number = req_data["contact_number"]
        address = req_data["address"]

        err = None
        db_conn = get_mysql_db()

        if (
                db_conn.execute(
                    "SELECT id FROM mvp.t_community_base WHERE community_name = ? and is_delete=0"
                , (cmnt_name,)).fetchone()
                is not None
        ):
            err = "User {0} is already registered.".format(cmnt_name)

        if not err:
            try:
                db_conn.execute(
                    "INSERT INTO mvp.t_community_base "
                    " (community_name, property_id, address, contact_number) "
                    " VALUES (?, ?, ?, ?)",
                    (cmnt_name, ppt_id, address, contact_number)
                )
                db_conn.commit()
            except Exception as ex:
                err = str(ex)

        if err:
            return jsonify(code=ReturnCode.FAIL.value, msg=err)


        return jsonify(code=ReturnCode.SUCCESS.value, msg="")