<commit_before>from flask import Flask, request, render_template, redirect, url_for, session, g, abort, flash, make_response, jsonify, Response
from datetime import timedelta, datetime
from models import IDC, Asset, User, app_host, application, App_product, db
from common.utility import  auth_login_required, hashpass, login_required
from common.util import dbdel, abort_if_id_doesnt_exist
from common.restful import  Serialization
from common.token_manage import Token_Manager
from app import app
from config import cross_origin


task = Serialization()
tokenauth = Token_Manager()


@app.route('/api/v1/product',methods=['GET'])
@cross_origin()
@auth_login_required
def product():
    if request.method == 'GET':
        '''
           查询产品线信息
           {  "info": "product 1 add success!",   "message": "OK",   "result": {    "product_name": "jltest",     "product_note": "note",     "product_user": "zhxiaohe"  },   "status": "200"}
        '''
        data =[ {'product_id':pduct.product_id,'product_name': pduct.product_name,'product_user':pduct.product_user,'product_note':pduct.product_note} for pduct in App_product.query.all() ]
        return task.json_message_200(data), 200


@app.route('/api/v1/product',methods=['POST'])
@cross_origin()
@auth_login_required
def product_add():
    if request.method == 'POST':
        '''
           新增产品线
        '''
        args = request.json
        data = App_product(**args)
        db.session.add(data)
        db.session.commit()
        mes = {'product_name':data.product_name,'product_note':data.product_note,'product_user':data.product_user}
        info = 'product %s add success!' % data.product_name
        return task.json_message_200(data=mes,info=info), 200



@app.route('/api/v1/product/<int:id>',methods=['GET'])
@cross_origin()
@auth_login_required
def product_app(id):
    '''
       查询产品线下的应用
       { "info": "", "message": "OK", "result": [ { "appname": "JGdepository", "appnote": "backend", "asset": [ "172.16.1.5", "172.16.1.6", "172.16.1.5" ] }
    '''
    if request.method == 'GET':
        appli = App_product.query.filter_by(product_id=id).first()
        data = [ {'appname':i.app_name,'appnote':i.app_note,'asset':[ ass.system_ip for ass in i.app_asset]} for i in appli.app_product ]
        return task.json_message_200(data), 200


@app.route('/api/v1/apps/',methods=['GET'])
@cross_origin()
@auth_login_required
def apps_list():
    '''
       查询所有应用信息
    '''
    if request.method == 'GET':
        data = [ {'appname':i.app_name,'appnote':i.app_note,'asset':[ ass.system_ip for ass in i.app_asset]} for i in application.query.all() ]
        return task.json_message_200(data), 200


@app.route('/api/v1/apps/',methods=['POST'])
@cross_origin()
@auth_login_required
def apps():
    '''
       新增应用并且绑定产品线
       {"app_name":"JGfinance","app_note":"JGfinance","app_product":1}  #productid为产品线主键
        or
       {'app_product': '1', 'app_user': 'CFCA', 'app_note': '%E7%94%B5%E5%AD%90%E7%AD%BE%E7%AB%A0', 'app_name': 'CFCA', 'app_asset': ['3', '4']}
    '''
    if request.method == 'POST':<commit_msg>新增查询应用函数<commit_after>from flask import Flask, request, render_template, redirect, url_for, session, g, abort, flash, make_response, jsonify, Response
from datetime import timedelta, datetime
from models import IDC, Asset, User, app_host, application, App_product, db
from common.utility import  auth_login_required, hashpass, login_required
from common.util import dbdel, abort_if_id_doesnt_exist
from common.restful import  Serialization
from common.token_manage import Token_Manager
from app import app
from config import cross_origin


task = Serialization()
tokenauth = Token_Manager()


@app.route('/api/v1/product',methods=['GET'])
@cross_origin()
@auth_login_required
def product():
    if request.method == 'GET':
        '''
           查询产品线信息
           {  "info": "product 1 add success!",   "message": "OK",   "result": {    "product_name": "jltest",     "product_note": "note",     "product_user": "zhxiaohe"  },   "status": "200"}
        '''
        data =[ {'product_id':pduct.product_id,'product_name': pduct.product_name,'product_user':pduct.product_user,'product_note':pduct.product_note} for pduct in App_product.query.all() ]
        return task.json_message_200(data), 200


@app.route('/api/v1/product',methods=['POST'])
@cross_origin()
@auth_login_required
def product_add():
    if request.method == 'POST':
        '''
           新增产品线
        '''
        args = request.json
        data = App_product(**args)
        db.session.add(data)
        db.session.commit()
        mes = {'product_name':data.product_name,'product_note':data.product_note,'product_user':data.product_user}
        info = 'product %s add success!' % data.product_name
        return task.json_message_200(data=mes,info=info), 200



@app.route('/api/v1/product/<int:id>',methods=['GET'])
@cross_origin()
@auth_login_required
def product_app(id):
    '''
       查询产品线下的应用
       { "info": "", "message": "OK", "result": [ { "appname": "JGdepository", "appnote": "backend", "asset": [ "172.16.1.5", "172.16.1.6", "172.16.1.5" ] }
    '''
    if request.method == 'GET':
        appli = App_product.query.filter_by(product_id=id).first()
        data = [ {'appname':i.app_name,'appnote':i.app_note,'asset':[ ass.system_ip for ass in i.app_asset]} for i in appli.app_product ]
        return task.json_message_200(data), 200


@app.route('/api/v1/apps/',methods=['GET'])
@cross_origin()
@auth_login_required
def apps_listall():
    '''
       查询所有应用信息
    '''
    if request.method == 'GET':
        data = [ {'app_id':i.app_id,'appname':i.app_name,'appnote':i.app_note,'asset':[ ass.system_ip for ass in i.app_asset]} for i in application.query.all() ]
        return task.json_message_200(data), 200


@app.route('/api/v1/apps/<int:id>',methods=['GET'])
@cross_origin()
@auth_login_required
def apps_list(id):
    '''
       查询某个应用信息
       {"info": "", "message": "OK", "result": {"appname": "test", "appnote": "test", "app_product": "", "asset": []}, "status": "200"}
    '''
    if request.method == 'GET':
        i = application.query.filter_by(app_id=id).first()
        #product =  {i.app_product.product_name:i.app_product.product_id}
        if i.appproduct:
            product = {i.appproduct.product_name:i.app_product}
        else:
            product = ""
        data = {'app_id':i.app_id,'app_name':i.app_name,'app_note':i.app_note,'app_product':product,'asset':[ ass.system_ip for ass in i.app_asset]}
        return task.json_message_200(data), 200


@app.route('/api/v1/apps/',methods=['POST'])
@cross_origin()
@auth_login_required
def apps():
    '''
       新增应用并且绑定产品线
       {"app_name":"JGfinance","app_note":"JGfinance","app_product":1}  #productid为产品线主键
        or
       {'app_product': '1', 'app_user': 'CFCA', 'app_note': '%E7%94%B5%E5%AD%90%E7%AD%BE%E7%AB%A0', 'app_name': 'CFCA', 'app_asset': ['3', '4']}
    '''
    if request.method == 'POST':
{'fraction_non_alphanumeric': 0.1703012912482066, 'fraction_numerical': 0.020946915351506456, 'mean_word_length': 3.8782365290412875, 'pattern_counts': {'":': 40, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7643345', 'n_tokens_mistral': 2540, 'n_tokens_neox': 2477, 'n_words': 450}