Exemplo n.º 1
0
    def post(self):
        body_data = request.form
        author_id = body_data.get('author_id', None)
        if not author_id:
            return jsonify("参数错误,HAS NO AUTHORID.")
        # 查找用户
        db_connection = MySQLConnection()
        cursor = db_connection.get_cursor()
        select_user_statement = "SELECT `id`,`name`,`is_admin` FROM `user_info` WHERE `id`=%s AND `is_active`=1;"
        cursor.execute(select_user_statement, author_id)
        user_obj = cursor.fetchone()
        if not user_obj:
            return jsonify("系统没有查到您的信息,无法操作."), 400
        if user_obj['is_admin']:
            return jsonify('请不要使用用管理员用户添加记录.')
        # 不为空的信息判断
        title = body_data.get('title', False)
        if not title:
            return jsonify("参数错误,NOT FOUND TITLE"), 400
        # 组织信息
        upload_time = body_data.get('upload_time')
        upload_time = datetime.datetime.strptime(
            upload_time,
            '%Y-%m-%d') if upload_time else datetime.datetime.now()
        author_id = user_obj['id']
        words = body_data.get('words', 0)
        is_publish = body_data.get('is_publish', False)
        level = body_data.get('level', 'C')
        score = body_data.get('score', 0)
        note = body_data.get('work_note', '')
        partner = body_data.get('partner_name', '')
        # 读取文件
        annex_file = request.files.get('annex_file', None)
        if not annex_file:
            filename = ''
            annex_url = ''
            file_path = ''
        else:
            # 文件名hash
            filename = annex_file.filename
            hash_name = hash_file_name(filename)
            # 获取保存的位置
            file_path = os.path.join(BASE_DIR,
                                     "fileStore/monographic/" + hash_name)
            annex_url = "fileStore/monographic/" + hash_name  # 数据库路径
            annex_file.save(file_path)
        # 存入数据库
        save_work_statement = "INSERT INTO `monographic`" \
                              "(`custom_time`,`author_id`,`title`,`words`,`is_publish`,`level`," \
                              "`score`,`note`,`partner`,`annex`,`annex_url`)" \
                              "VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
        try:
            # 转换类型
            words = int(words) if words else 0
            score = int(score) if score else 0
            is_publish = 1 if is_publish else 0
            cursor.execute(save_work_statement,
                           (upload_time, author_id, title, words, is_publish,
                            level, score, note, partner, filename, annex_url))
            db_connection.commit()

        except Exception as e:
            db_connection.rollback()
            db_connection.close()
            current_app.logger.error("写入专题研究记录错误:" + str(e))
            # 保存错误得删除已保存的文件
            if file_path and os.path.exists(file_path):
                os.remove(file_path)
            return jsonify("参数错误!无法保存。"), 400
        else:
            db_connection.close()
            return jsonify("保存成功!"), 201
Exemplo n.º 2
0
    def post(self):
        body_data = request.form
        worker_id = body_data.get('worker_id', None)
        if not worker_id:
            return jsonify("参数错误,HAS NO WORKERID.")
        # 查找用户
        db_connection = MySQLConnection()
        cursor = db_connection.get_cursor()
        select_user_statement = "SELECT `id`,`name`,`is_admin` FROM `user_info` WHERE `id`=%s;"
        cursor.execute(select_user_statement, worker_id)
        user_obj = cursor.fetchone()
        # 管理员不给添加信息
        if user_obj['is_admin']:
            return jsonify('请不要使用用管理员用户添加记录.')
        # 不为空的信息判断
        task_type = body_data.get('task_type', 0)
        task_type_text = ABNORMAL_WORK.get(int(task_type), 0)
        title = body_data.get('work_title', False)
        if not task_type_text or not title:
            return jsonify("参数错误,NOT FOUND TASKTYPE AND TITLE"), 400
        # 组织信息
        custom_time = datetime.datetime.strptime(body_data.get('work_date'), '%Y-%m-%d')
        worker = user_obj['id']
        sponsor = body_data.get('sponsor', '')
        applied_org = body_data.get('applicat_org', '')
        applicant = body_data.get('application_person', '')
        tel_number = body_data.get('link_number', '')
        swiss_coin = body_data.get('ruibi_count', 0)
        allowance = body_data.get('income_allowance', 0)
        note = body_data.get('work_note', '')
        partner = body_data.get('partner_name', '')
        # 读取文件
        annex_file = request.files.get('annex_file', None)
        if not annex_file:
            filename = ''
            annex_url = ''
            file_path = ''
        else:
            # 文件名hash
            filename = annex_file.filename
            hash_name = hash_file_name(filename)
            # 获取保存的位置
            file_path = os.path.join(BASE_DIR, "fileStore/abwork/" + hash_name)
            annex_url = "fileStore/abwork/" + hash_name  # 数据库路径
            annex_file.save(file_path)
        # 存入数据库
        save_work_statement = "INSERT INTO `abnormal_work`" \
                              "(`custom_time`,`author_id`,`task_type`,`title`,`sponsor`,`applied_org`," \
                              "`applicant`,`tel_number`,`swiss_coin`,`allowance`,`note`,`partner`,`annex`,`annex_url`)" \
                              "VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
        try:
            swiss_coin = int(swiss_coin) if swiss_coin else 0
            allowance = float(allowance) if allowance else 0
            cursor.execute(save_work_statement,
                           (custom_time, worker, task_type, title, sponsor, applied_org,
                            applicant, tel_number, swiss_coin, allowance, note, partner, filename, annex_url)
                           )
            db_connection.commit()

        except Exception as e:
            db_connection.rollback()
            db_connection.close()
            current_app.logger.error("写入非常态工作错误:" + str(e))
            # 保存错误得删除已保存的文件
            if file_path and os.path.exists(file_path):
                os.remove(file_path)
            return jsonify("参数错误!无法保存。"), 400
        else:
            db_connection.close()
            return jsonify("保存成功!"), 201
Exemplo n.º 3
0
    def put(self, rid):
        body_data = request.form
        utoken = body_data.get('utoken')
        user_info = verify_json_web_token(utoken)
        user_id = user_info['uid']
        # 不为空的信息判断
        title = body_data.get('title', False)
        if not title:
            return jsonify("参数错误,NOT FOUND TITLE"), 400
        # 组织信息
        custom_time = body_data.get('custom_time')
        words = body_data.get('words', 0)
        is_publish = body_data.get('is_publish', False)
        level = body_data.get('level', 'D')
        score = body_data.get('score', 0)
        note = body_data.get('note', '')
        partner = body_data.get('partner_name', '')

        filename = body_data.get('annex', '')
        annex_url = body_data.get('annex_url', '')
        old_annex_url = annex_url
        annex_file = request.files.get('annex_file', None)
        file_path = ''
        if annex_file:
            filename = annex_file.filename
            hash_name = hash_file_name(filename)
            file_path = os.path.join(BASE_DIR,
                                     "fileStore/monographic/" + hash_name)
            annex_url = "fileStore/monographic/" + hash_name  # 数据库路径
            annex_file.save(file_path)
        update_statement = "UPDATE `monographic` SET " \
                           "`custom_time`=%s,`title`=%s,`words`=%s,`is_publish`=%s,`level`=%s," \
                           "`score`=%s,`note`=%s,`partner`=%s,`annex`=%s,`annex_url`=%s " \
                           "WHERE `id`=%s AND `author_id`=%s;"
        db_connection = MySQLConnection()
        try:
            # 转换类型
            custom_time = datetime.datetime.strptime(custom_time, '%Y-%m-%d')
            words = int(words) if words else 0
            score = int(score) if score else 0
            is_publish = 1 if is_publish else 0
            cursor = db_connection.get_cursor()
            cursor.execute(
                update_statement,
                (custom_time, title, words, is_publish, level, score, note,
                 partner, filename, annex_url, rid, user_id))
            db_connection.commit()
            old_file_path = os.path.join(BASE_DIR, old_annex_url)
            if annex_file and os.path.isfile(old_file_path):  # 有新文件才能删除旧文件
                os.remove(old_file_path)
        except Exception as e:
            db_connection.rollback()
            db_connection.close()
            current_app.logger.error("修改专题研究记录错误:" + str(e))
            # 保存错误得删除已保存的文件
            if file_path and os.path.isfile(file_path):
                os.remove(file_path)
            return jsonify("参数错误!无法保存。")
        else:
            db_connection.close()
            return jsonify("修改成功!")
Exemplo n.º 4
0
 def put(self, work_id):
     body_data = request.form
     utoken = body_data.get('utoken')
     user_info = verify_json_web_token(utoken)
     user_id = user_info['uid']
     # 不为空的信息判断
     task_type = body_data.get('task_type', 0)
     task_type_text = ABNORMAL_WORK.get(int(task_type), 0)
     title = body_data.get('title', False)
     if not task_type_text or not title:
         return jsonify("参数错误,NOT FOUND TASKTYPE AND TITLE"), 400
     # 组织信息
     custom_time = datetime.datetime.strptime(body_data.get('custom_time'), '%Y-%m-%d')
     task_type = body_data.get('task_type', 0)
     sponsor = body_data.get('sponsor', '')
     applied_org = body_data.get('applied_org', '')
     applicant = body_data.get('applicant', '')
     tel_number = body_data.get('tel_number', '')
     swiss_coin = body_data.get('swiss_coin', 0)
     allowance = body_data.get('allowance', 0)
     note = body_data.get('note', '')
     partner = body_data.get('partner_name', '')
     filename = body_data.get('annex','')
     annex_url = body_data.get('annex_url','')
     old_annex_url = annex_url  # 保存旧文件路径待删除文件
     # 读取文件
     annex_file = request.files.get('annex_file', None)
     file_path = ''
     if annex_file:
         filename = annex_file.filename
         hash_name = hash_file_name(filename)
         # 获取保存的位置
         file_path = os.path.join(BASE_DIR, "fileStore/abwork/" + hash_name)
         annex_url = "fileStore/abwork/" + hash_name  # 数据库路径
         annex_file.save(file_path)
     # 存入数据库
     update_statement = "UPDATE `abnormal_work` SET " \
                         "`custom_time`=%s,`task_type`=%s,`title`=%s,`sponsor`=%s,`applied_org`=%s," \
                         "`applicant`=%s,`tel_number`=%s,`swiss_coin`=%s,`allowance`=%s,`note`=%s,`partner`=%s," \
                         "`annex`=%s,`annex_url`=%s " \
                         "WHERE `id`=%s AND `author_id`=%s;"
     db_connection = MySQLConnection()
     try:
         swiss_coin = int(swiss_coin) if swiss_coin else 0
         allowance = float(allowance) if allowance else 0
         cursor = db_connection.get_cursor()
         cursor.execute(update_statement,
                        (custom_time, task_type, title, sponsor, applied_org,
                         applicant, tel_number, swiss_coin, allowance, note, partner,
                         filename,annex_url,
                         work_id, user_id)
                        )
         db_connection.commit()
         # 删除原来的文件
         old_file_path = os.path.join(BASE_DIR, old_annex_url)
         if annex_file and os.path.isfile(old_file_path):
             os.remove(old_file_path)
     except Exception as e:
         db_connection.rollback()
         db_connection.close()
         current_app.logger.error("修改非常态工作记录错误:" + str(e))
         if file_path and os.path.exists(file_path):
             os.remove(file_path)
         return jsonify("参数错误!无法修改。"), 400
     else:
         db_connection.close()
         return jsonify("修改成功!")
Exemplo n.º 5
0
    def post(self):
        body_data = request.form
        author_id = body_data.get('author_id', None)
        if not author_id:
            return jsonify("参数错误,HAS NO AUTHORID.")
        # 查找用户
        db_connection = MySQLConnection()
        cursor = db_connection.get_cursor()
        select_user_statement = "SELECT `id`,`name`,`is_admin` FROM `user_info` WHERE `id`=%s AND `is_active`=1;"
        cursor.execute(select_user_statement, author_id)
        user_obj = cursor.fetchone()
        if not user_obj:
            return jsonify("系统没有查到您的信息,无法操作."), 400
        if user_obj['is_admin']:
            return jsonify('请不要使用用管理员用户添加记录.')
        # 不为空的信息判断
        title = body_data.get('title', False)
        if not title:
            return jsonify("参数错误,NOT FOUND TITLE."), 400

        # 组织信息
        custom_time = body_data.get('custom_time')
        custom_time = datetime.datetime.strptime(
            custom_time,
            '%Y-%m-%d') if custom_time else datetime.datetime.now()
        author_id = user_obj['id']
        media_name = body_data.get('media_name', '')
        rough_type = body_data.get('rough_type', '')
        words = body_data.get('words', 0)
        checker = body_data.get('checker', '')
        allowance = body_data.get('allowance', 0)
        partner = body_data.get('partner', '')
        note = body_data.get('note', '')
        # 读取文件
        annex_file = request.files.get('annex_file', None)
        if not annex_file:
            filename = ''
            annex_url = ''
            file_path = ''
        else:
            # 文件名hash
            filename = annex_file.filename
            hash_name = hash_file_name(filename)
            # 获取保存的位置
            file_path = os.path.join(BASE_DIR,
                                     "fileStore/artpublish/" + hash_name)
            annex_url = "fileStore/artpublish/" + hash_name  # 数据库路径
            annex_file.save(file_path)
        # 存入数据库
        save_invest_statement = "INSERT INTO `article_publish`" \
                              "(`custom_time`,`author_id`,`title`,`media_name`,`rough_type`,`words`,`checker`," \
                              "`allowance`,`partner`,`note`,`annex`,`annex_url`)" \
                              "VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
        try:
            # 转换类型
            words = int(words) if words else 0
            allowance = int(allowance) if allowance else 0
            cursor.execute(
                save_invest_statement,
                (custom_time, author_id, title, media_name, rough_type, words,
                 checker, allowance, partner, note, filename, annex_url))
            db_connection.commit()

        except Exception as e:
            db_connection.rollback()
            db_connection.close()
            current_app.logger.error("写入文章审核记录错误:" + str(e))
            # 保存错误得删除已保存的文件
            if file_path and os.path.exists(file_path):
                os.remove(file_path)
            return jsonify("参数错误!无法保存。"), 400
        else:
            db_connection.close()
            return jsonify("保存成功!"), 201
Exemplo n.º 6
0
    def put(self, rid):
        body_data = request.form
        utoken = body_data.get('utoken')
        user_info = verify_json_web_token(utoken)
        user_id = user_info['uid']
        # 不为空的信息判断
        title = body_data.get('title', False)
        if not title:
            return jsonify("参数错误,NOT FOUND TITLE."), 400

        # 组织信息
        custom_time = body_data.get('custom_time')
        media_name = body_data.get('media_name', '')
        rough_type = body_data.get('rough_type', '')
        words = body_data.get('words', 0)
        checker = body_data.get('checker', '')
        allowance = body_data.get('allowance', 0)
        partner = body_data.get('partner', '')
        note = body_data.get('note', '')

        filename = body_data.get('annex', '')
        annex_url = body_data.get('annex_url', '')
        old_annex_url = annex_url
        annex_file = request.files.get('annex_file', None)
        file_path = ''
        if annex_file:
            filename = annex_file.filename
            hash_name = hash_file_name(filename)
            file_path = os.path.join(BASE_DIR,
                                     "fileStore/artpublish/" + hash_name)
            annex_url = "fileStore/artpublish/" + hash_name  # 数据库路径
            annex_file.save(file_path)
        # 更新数据库
        update_statement = "UPDATE `article_publish` SET " \
                            "`custom_time`=%s,`title`=%s,`media_name`=%s,`rough_type`=%s,`words`=%s,`checker`=%s," \
                            "`allowance`=%s,`partner`=%s,`note`=%s,`annex`=%s,`annex_url`=%s " \
                            "WHERE `id`=%s AND `author_id`=%s;"
        db_connection = MySQLConnection()
        try:
            # 转换类型
            user_id = int(user_id)
            custom_time = datetime.datetime.strptime(
                custom_time,
                '%Y-%m-%d') if custom_time else datetime.datetime.now()
            words = int(words) if words else 0
            allowance = int(allowance) if allowance else 0

            cursor = db_connection.get_cursor()
            cursor.execute(
                update_statement,
                (custom_time, title, media_name, rough_type, words, checker,
                 allowance, partner, note, filename, annex_url, rid, user_id))
            db_connection.commit()
            old_file_path = os.path.join(BASE_DIR, old_annex_url)
            if annex_file and os.path.isfile(old_file_path):
                os.remove(old_file_path)

        except Exception as e:
            db_connection.rollback()
            db_connection.close()
            current_app.logger.error("修改文章审核记录错误:" + str(e))
            if file_path and os.path.exists(file_path):
                os.remove(file_path)
            return jsonify("参数错误!无法修改。"), 400
        else:
            db_connection.close()
            return jsonify("修改成功!")
Exemplo n.º 7
0
    def post(self):
        body_data = request.form
        author_id = body_data.get('author_id', None)
        if not author_id:
            return jsonify("参数错误,HAS NO AUTHORID.")
        # 查找用户
        db_connection = MySQLConnection()
        cursor = db_connection.get_cursor()
        select_user_statement = "SELECT `id`,`name`,`is_admin` FROM `user_info` WHERE `id`=%s AND `is_active`=1;"
        cursor.execute(select_user_statement, author_id)
        user_obj = cursor.fetchone()
        if not user_obj:
            return jsonify("系统没有查到您的信息,无法操作."), 400
        if user_obj['is_admin']:
            return jsonify('请不要使用用管理员用户添加记录.')
        # 不为空的信息判断
        title = body_data.get('title', False)
        variety = body_data.get('variety', False)
        direction = body_data.get('direction', False)
        if not title or not variety or not direction:
            return jsonify("参数错误,NOT FOUND TITLE,VARIETY,DIRECTION."), 400
        # 组织信息
        write_time = body_data.get('write_time')
        author_id = user_obj['id']
        contract = body_data.get('contract','')
        build_time = body_data.get('build_date_time')
        build_price = body_data.get('build_price')
        build_hands = body_data.get('build_hands')
        out_price = body_data.get('out_price')
        cutloss_price = body_data.get('cutloss_price')
        expire_time = body_data.get('expire_time')
        is_publish = 1 if body_data.get('is_publish', False) else 0
        profit = body_data.get('profit')
        level = body_data.get('level', '')
        note = body_data.get('note', '')
        # 读取文件
        annex_file = request.files.get('annex_file', None)
        if not annex_file:
            filename = ''
            annex_url = ''
            file_path = ''
        else:
            # 文件名hash
            filename = annex_file.filename
            hash_name = hash_file_name(filename)
            # 获取保存的位置
            file_path = os.path.join(BASE_DIR, "fileStore/investment/" + hash_name)
            annex_url = "fileStore/investment/" + hash_name  # 数据库路径
            annex_file.save(file_path)
        # 存入数据库
        save_invest_statement = "INSERT INTO `investment`" \
                              "(`custom_time`,`author_id`,`title`,`variety_id`,`contract`,`direction`,`build_time`," \
                              "`build_price`,`build_hands`,`out_price`,`cutloss_price`,`expire_time`,`is_publish`,`profit`,`annex`,`annex_url`,`note`,`level`)" \
                              "VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
        try:
            # 转换类型
            custom_time = datetime.datetime.strptime(write_time, '%Y-%m-%d') if write_time else datetime.datetime.now()
            build_time = datetime.datetime.strptime(build_time,'%Y-%m-%dT%H:%M') if build_time else datetime.datetime.now()
            expire_time = datetime.datetime.strptime(expire_time,'%Y-%m-%dT%H:%M') if expire_time else datetime.datetime.now()
            variety_id = int(variety)
            build_price = float(build_price) if build_price else 0
            build_hands = int(build_hands) if build_hands else 0
            out_price = float(out_price) if out_price else 0
            cutloss_price = float(cutloss_price) if cutloss_price else 0
            profit = float(profit) if profit else 0
            cursor.execute(save_invest_statement,
                           (custom_time, author_id, title, variety_id,contract, direction, build_time,
                            build_price, build_hands, out_price, cutloss_price, expire_time, is_publish, profit, filename,annex_url,note, level)
                           )
            db_connection.commit()

        except Exception as e:
            db_connection.rollback()
            db_connection.close()
            current_app.logger.error("写入投在方案记录错误:" + str(e))
            # 保存错误得删除已保存的文件
            if file_path and os.path.exists(file_path):
                os.remove(file_path)
            return jsonify("参数错误!无法保存。"), 400
        else:
            db_connection.close()
            return jsonify("保存成功!"), 201
Exemplo n.º 8
0
    def put(self, rid):
        body_data = request.form
        utoken = body_data.get('utoken')
        user_info = verify_json_web_token(utoken)
        user_id = user_info['uid']
        # 不为空的信息判断
        title = body_data.get('title', False)
        variety_id = body_data.get('variety_id', False)
        direction = body_data.get('direction', False)
        if not title or not variety_id or not direction:
            return jsonify("参数错误,NOT FOUND TITLE,VARIETY,DIRECTION."), 400
        # 组织信息
        write_time = body_data.get('custom_time')
        contract = body_data.get('contract', '')
        build_time = body_data.get('build_time')
        build_price = body_data.get('build_price')
        build_hands = body_data.get('build_hands')
        out_price = body_data.get('out_price')
        cutloss_price = body_data.get('cutloss_price')
        expire_time = body_data.get('expire_time')
        is_publish = 1 if body_data.get('is_publish', False) else 0
        profit = body_data.get('profit')
        note = body_data.get('note', '')
        level = body_data.get('level', '')
        filename=body_data.get('annex', '')
        annex_url = body_data.get('annex_url', '')
        old_annex_url = annex_url
        annex_file = request.files.get('annex_file', None)
        file_path = ''
        if annex_file:
            filename = annex_file.filename
            hash_name = hash_file_name(filename)
            file_path = os.path.join(BASE_DIR, "fileStore/investment/" + hash_name)
            annex_url = "fileStore/investment/" + hash_name  # 数据库路径
            annex_file.save(file_path)

        # 存入数据库
        update_statement = "UPDATE `investment` SET " \
                            "`custom_time`=%s,`title`=%s,`variety_id`=%s,`contract`=%s,`direction`=%s,`build_time`=%s," \
                            "`build_price`=%s,`build_hands`=%s,`out_price`=%s,`cutloss_price`=%s,`expire_time`=%s," \
                            "`is_publish`=%s,`profit`=%s,`annex`=%s,`annex_url`=%s,`note`=%s,`level`=%s " \
                            "WHERE `id`=%s AND `author_id`=%s;"
        db_connection = MySQLConnection()
        cursor = db_connection.get_cursor()
        try:
            # 转换类型
            variety_id = int(variety_id)
            build_price = float(build_price) if build_price else 0
            build_hands = int(build_hands) if build_hands else 0
            out_price = float(out_price) if out_price else 0
            cutloss_price = float(cutloss_price) if cutloss_price else 0
            profit = float(profit) if profit else 0
            expire_time_format = build_time_format = '%Y-%m-%dT%H:%M:%S'
            if len(build_time) < 19:
                build_time_format = '%Y-%m-%dT%H:%M'
            if len(expire_time) < 19:
                expire_time_format = '%Y-%m-%dT%H:%M'
            custom_time = datetime.datetime.strptime(write_time, '%Y-%m-%d') if write_time else datetime.datetime.now()
            build_time = datetime.datetime.strptime(build_time,build_time_format) if build_time else datetime.datetime.now()
            expire_time = datetime.datetime.strptime(expire_time,expire_time_format) if expire_time else datetime.datetime.now()
            cursor.execute(update_statement,
                           (custom_time, title, variety_id, contract, direction, build_time,
                            build_price, build_hands, out_price, cutloss_price, expire_time, is_publish, profit,filename, annex_url,note,level,
                            rid, user_id)
                           )
            db_connection.commit()
            old_file_path = os.path.join(BASE_DIR, old_annex_url)
            if annex_file and os.path.isfile(old_file_path):
                os.remove(old_file_path)
        except Exception as e:
            db_connection.rollback()
            db_connection.close()
            current_app.logger.error("更新投资方案记录错误:" + str(e))
            if file_path and os.path.exists(file_path):
                os.remove(file_path)
            return jsonify("参数错误!无法更新。"), 400
        else:
            db_connection.close()
            return jsonify("更新成功!"), 201