def test4(self):
     goods_dao = GoodsDao()
     add = goods_dao.add("手机", 20, "1", "电子", "kg")
     # res = goods_dao.query_all()
     # res = goods_dao.query_by_companyId('1', '苹', None)
     # j = json.dumps(return_success({'goodsList': GoodsDao.to_dict(res)}), cls=DecimalEncoder, ensure_ascii=False)
     print(add)
Exemple #2
0
 def test15(self):
     query = SellDao()
     queryCustomer = CustomerDao()
     queryGoods = GoodsDao()
     companyId = "5"
     customerId = "201353eb-4f3b-3992-bdae-347841dc304d"
     result = queryCustomer.query_byId(customerId)
     if len(result) == 1:
         customerName = result[0][1]
     else:
         customerName = ""
     sumprice = 22.5
     date = "2019-7-12"
     id = str(uuid.uuid3(uuid.NAMESPACE_OID, date))
     goodsId = "e7f00942-5aad-3df5-90d1-c850b0839ff2"
     number = 5
     goodsResult = queryGoods.query_byId(goodsId)
     if len(goodsResult) == 1:
         goodsName = goodsResult[0][1]
     else:
         goodsName = ""
     row = query.add(id, customerId, goodsId, companyId, number, sumprice,
                     date, customerName, goodsName)
     if row == 1:
         return json.dumps(return_success("Yes!"))
     else:
         return json.dumps(return_unsuccess('Error: Add failed'))
def upload():
    file_dir = os.path.join(basedir, UPLOAD_FOLDER)
    if not os.path.exists(file_dir):
        os.makedirs(file_dir)
    f, = request.files.values()
    _id = request.form.get("id")
    print(_id)
    size = len(f.read())
    print(size)
    f.seek(0)
    if f and allowed_file(f.filename):
        if size <= MAX_CONTENT_LENGTH:
            fname = secure_filename(f.filename)
            print(fname)
            ext = fname.rsplit('.', 1)[1]
            new_filename = Pic_str().create_uuid() + '.' + ext
            # 更新photo
            try:
                goods_dao = GoodsDao()
                goods_dao.update_photo(_id, new_filename)
                # 保存图片到本地
                f.save(os.path.join(file_dir, new_filename))
                f.close()
                return json.dumps(return_success({"new_filename": new_filename}), ensure_ascii=False)
            except Exception as e:
                return json.dumps(return_unsuccess({"new_filename": new_filename, 'Update Error': str(e)}),
                                  ensure_ascii=False)
        else:
            return json.dumps(return_unsuccess("文件大小超出5MB"), ensure_ascii=False)
    else:
        return json.dumps(return_unsuccess("文件格式不正确"), ensure_ascii=False)
def GetPicPurchasePrice(goodsType, purchaseResult):
    sumPriceByType = []
    sumNumByType = []
    for gType in goodsType:
        sumOneType = 0
        sumOneNum = 0
        sumPrice = 0
        for sellRecord in purchaseResult:
            goodsList = sellRecord['goodsList']
            for goods in goodsList:
                goodsId = goods['goodsId']
                queryGoodsType = GoodsDao()
                sumPrice = sumPrice + goods['number'] * goods['price']
                goodType = queryGoodsType.queryType_byId(goodsId)
                if goodType[0][0] == gType:
                    sumOneType = sumOneType + goods['number'] * goods['price']
                    sumOneNum = sumOneNum + goods['number']
        sumPriceByType.append(sumOneType)
        sumNumByType.append(sumOneNum)
    datas = {}
    ah = {}
    datas['type'] = 'pie'
    datas['summary'] = '进货状况饼状图'
    print(len(goodsType))
    for i in range(0, len(sumPriceByType)):
        ah[goodsType[i]] = sumPriceByType[i]
    datas['diagram'] = ah
    return datas, len(goodsType), sumPrice
def getPurchaseData(Purchase, time, start, end):
    finalResult = []
    if Purchase['success'] == True:
        purchaseResult = Purchase['result']
        print(purchaseResult)
        groups = []
        goodsType = []
        group = {}
        activeNames = []
        items = []
        for sellRecord in purchaseResult:
            item = {}
            goodsList = sellRecord['goodsList']
            lists = []
            content = {}
            for goods in goodsList:
                goodsId = goods['goodsId']
                queryGoodsType = GoodsDao()
                goodType = queryGoodsType.queryType_byId(goodsId)
                if goodType[0][0] not in goodsType:
                    goodsType.append(goodType[0][0])
                list = {}
                list['title'] = goods['goodsName']
                list['value'] = goods['number']
                list['label'] = goods['goodsId']
                lists.append(list)
            content['type'] = 'list'
            content['lists'] = lists
            item['title'] = sellRecord['date']
            item['value'] = '供货商' + sellRecord['supplierName']
            item['label'] = sellRecord['id']
            item['content'] = content
            items.append(item)
        group['activeNames'] = activeNames
        group['items'] = items
        # 调用获取图片信息的函数
        GetPicPurchasePriceResult = GetPicPurchasePrice(
            goodsType, purchaseResult)
        finalResult.append(GetPicPurchasePriceResult[0])
        if time == 'this_month':
            finalResult.append(GetPicturePurchaseData(start, end))
        groups.append(group)
        sellInfo = {
            'type':
            'collapse-group',
            'summary':
            '该段时间共进了' + str(GetPicPurchasePriceResult[1]) + '种货物,共计' +
            str(GetPicPurchasePriceResult[2]) + '元',
            'groups':
            groups
        }
        finalResult.append(sellInfo)
        print(finalResult)
        return json.dumps(return_success(finalResult),
                          ensure_ascii=False,
                          cls=DecimalEncoder)
    else:
        return json.dumps(return_unsuccess('不好意思,没有查到相关数据哦'))
Exemple #6
0
def addGoods():
    _json = request.json
    print(_json)
    goods_dao = GoodsDao()
    try:
        res = goods_dao.add(_json.get('name'), _json.get('sellprice'),
                            _json.get('companyId'), _json.get('type'),
                            _json.get('unitInfo'), _json.get('barcode'))
        return json.dumps(return_success({"id": res["id"]}))
    except Exception as e:
        print(e)
        return json.dumps(return_unsuccess("添加商品失败 " + str(e)),
                          ensure_ascii=False)
Exemple #7
0
def update_goods_info():
    _json = request.json
    goods_dao = GoodsDao()
    res = goods_dao.query_byId(_json.get('id'))
    if len(res) is not 1:
        return json.dumps(return_unsuccess("未找到该商品"), ensure_ascii=False)
    try:
        goods_dao.update_info(_json.get('id'), _json.get('name'),
                              _json.get('sellprice'), _json.get('type'),
                              _json.get('unitInfo'), _json.get('barcode'))
        return json.dumps(return_success("更新商品信息成功"), ensure_ascii=False)
    except Exception as e:
        print(e)
        return json.dumps(return_unsuccess("添加商品失败"), ensure_ascii=False)
Exemple #8
0
def queryGoodsStoreByGoodsId():
    _json = request.json
    company_id = _json.get('companyId')
    goods_id = _json.get('goodsId')
    goods_dao = GoodsDao()
    try:
        res = goods_dao.query_store_by_goods_id(company_id, goods_id)
        if len(res) > 0:
            return json.dumps(return_success(
                GoodsDao.to_ware_goods_amount_dict(res)),
                              ensure_ascii=False)
        else:
            return json.dumps(return_unsuccess("未找到该商品"), ensure_ascii=False)
    except Exception as e:
        return json.dumps(return_unsuccess("查询商品失败 " + str(e)),
                          ensure_ascii=False)
Exemple #9
0
def queryGoods():
    _json = request.json
    companyId = _json.get('companyId')
    name = _json.get('name')
    type = _json.get('type')
    id = _json.get('id')
    goods_dao = GoodsDao()
    result = goods_dao.query_by_companyId(companyId, name, type, id)
    size = len(result)
    if size >= 0:
        return json.dumps(return_success(
            {'goodsList': GoodsDao.to_dict(result)}),
                          cls=DecimalEncoder,
                          ensure_ascii=False)
    else:
        return json.dumps(return_unsuccess("查询失败"), ensure_ascii=False)
def query_by_warehouse():
    _json = request.json
    _companyId = _json.get("companyId")
    _wareHouseId = _json.get("wareHouseId")
    _name = _json.get('name')
    _type = _json.get('type')
    print(_json)
    goods_dao = GoodsDao()
    res = goods_dao.query_by_warehouse(_companyId, _wareHouseId, _name, _type)
    size = len(res)
    if size >= 0:
        return json.dumps(return_success(
            {'goodsList': GoodsDao.to_ware_dict(res)}),
                          cls=DecimalEncoder,
                          ensure_ascii=False)
    else:
        return jsonify(return_unsuccess("查询失败"))
Exemple #11
0
def addSell():
    conn = MyHelper()
    queryCustomer = CustomerDao()
    queryGoods = GoodsDao()
    _json = request.json
    params = []
    sqls = []
    companyId = _json.get('companyId')
    customerId = _json.get('customerId')
    result = queryCustomer.query_byId(customerId)
    if len(result) == 1:
        customerName = result[0][1]
    else:
        customerName = ""
    date = _json.get('date')
    goodsList = _json.get('goodsList')
    id = str(uuid.uuid3(uuid.NAMESPACE_OID, str(time.time())))
    # print(goodsList)
    for puchase in goodsList:
        sumprice = puchase['sumprice']
        goodsId = puchase['goodsId']
        number = puchase['number']
        goodsResult = queryGoods.query_byId(goodsId)
        if len(goodsResult) == 1:
            goodsName = goodsResult[0][1]
            goodsUnit = goodsResult[0][5]
        else:
            goodsName = ""
        params.append([
            id, customerId, goodsId, companyId, number, sumprice, date,
            customerName, goodsName, goodsUnit
        ])
        sqls.append(
            "insert into Sell (id,customerId, goodsId, companyId, number, sumprice,date,customerName,goodsName,unitInfo) "
            "values (%s, %s, %s, %s, %s,%s, %s, %s, %s, %s)")

    rows = conn.executeUpdateTransaction(sqls=sqls, params=params)
    if rows:
        return json.dumps(return_success(id))
    else:
        return json.dumps(return_unsuccess('Error: Add failed'))
Exemple #12
0
def queryPurchase():
    query = PurchaseDao()
    querySupplierName = SupplierDao()
    queryGoodsPhoto = GoodsDao()
    _json = request.json
    companyId = _json.get('companyId')
    results = []
    if _json.get('id') == None:
        if _json.get('date') == None:
            idResult = query.queryAllId(companyId)
        else:
            if _json.get('start') != None:
                start = _json.get('start')
                end = _json.get('end')
            else:
                date = _json.get('date')
                start = datetime.datetime.strptime(date, '%Y-%m-%d')
                delta = datetime.timedelta(days=1)
                n_days = start + delta
                end = n_days.strftime('%Y-%m-%d %H:%M:%S')
            idResult = query.query_byDate(companyId, start, end)
        size = len(idResult)
        if size == 0:
            return json.dumps(return_unsuccess('Error: No data'))
        else:
            for j in range(0, len(idResult)):
                result = []
                id = idResult[j][0]
                goodsList = []
                goodsResult = query.query_byId(id)
                for i in range(0, len(goodsResult)):
                    status = goodsResult[i][8]
                    supplierId = goodsResult[i][3]
                    PhothResult = queryGoodsPhoto.query_byId(goodsResult[i][1])
                    goodsPhoto = PhothResult[0][7]
                    NameResult = querySupplierName.query_byId(supplierId)
                    supplierName = NameResult[0][1]
                    date = goodsResult[i][7]
                    goods = []
                    goods.append(goodsResult[i][6])
                    goods.append(goodsResult[i][1])
                    goods.append(goodsPhoto)
                    goods.append(goodsResult[i][2])
                    goods.append(goodsResult[i][5])
                    goodsList.append(goods)
                result.append(id)
                result.append(status)
                result.append(supplierId)
                result.append(date)
                result.append(supplierName)
                result.append(goodsList)
                results.append(result)
    else:
        id = _json.get('id')
        result = []
        goodsList = []
        goodsResult = query.query_byId(id)
        if len(goodsResult) >= 0:
            for i in range(0, len(goodsResult)):
                status = goodsResult[i][8]
                supplierId = goodsResult[i][3]
                PhothResult = queryGoodsPhoto.query_byId(goodsResult[i][1])
                goodsPhoto = PhothResult[0][7]
                NameResult = querySupplierName.query_byId(supplierId)
                supplierName = NameResult[0][1]
                date = goodsResult[i][7]
                goods = []
                goods.append(goodsResult[i][6])
                goods.append(goodsResult[i][1])
                goods.append(goodsPhoto)
                goods.append(goodsResult[i][2])
                goods.append(goodsResult[i][5])
                goodsList.append(goods)
            result.append(id)
            result.append(status)
            result.append(supplierId)
            result.append(date)
            result.append(supplierName)
            result.append(goodsList)
            results.append(result)
    size = len(results)
    if size == 0:
        return json.dumps(return_unsuccess('Error: No data'))
    else:
        return json.dumps(return_success(PurchaseDao.to_dict(results)), ensure_ascii=False, cls=DecimalEncoder)
Exemple #13
0
 def test8(self):
     goods = GoodsDao()
     res = goods.query_by_warehouse("5", None)
     print(json.dumps(GoodsDao.to_ware_dict(res), cls=DecimalEncoder, ensure_ascii=False))
Exemple #14
0
 def test15(self):
     res = GoodsDao().query_store_by_goods_id('5', '81e40a91-6554-3605-824b-d944634c1d71')
     print(res)
Exemple #15
0
 def test14(self):
     res = GoodsDao().query_by_warehouse("5", None, None, None)
     print(res)
Exemple #16
0
    def test12(self):

        companyId = "5"
        date1 = "2019-07-24 19:11:03"
        date = "2019-07-24"
        d = datetime.datetime.strptime(date1, '%Y-%m-%d %H:%M:%S')
        language = ""
        jieba.load_userdict("../app/utils/dict.txt")
        # 去除停用词
        stopwords = {}.fromkeys(['的', '包括', '等', '是', '多少', "所有", "一下"])
        today = ['今天', '这一天']
        yesterday = ['昨天', '上一天']
        this_week = ['这周', '这一周']
        last_week = ['上周', '上一周']
        this_month = ['这个月']

        ac_in_money = ['赚', '挣', '卖', '收入', '盈利', '进账']
        ac_purchase = ['进', '买', "进了", "买了"]
        ac_query = ['查', '看', '查看', "查询"]
        ac_out_money = ['花', '消费', '支出']

        goods = ['东西', '商品', '货', "货物"]
        money = ['钱']
        price = ['价格']
        inPrice = ['进价']
        outPrice = ['售价']
        store = ['库存']
        supplier = ['供货商', '供应商', '进货商']
        customer = ['顾客', '客户']
        tables = ['利润表', '资产负债表', '经营日报', '利润分析']

        text1 = "这个月卖了什么货"
        text2 = "这个月挣了多少钱"
        text3 = "查一下商品可口可乐的售价"
        text4 = "这个月挣了多少钱"
        # 精确模式
        segs = jieba.cut(text3, cut_all=False)
        final = []
        for seg in segs:
            if seg not in stopwords:
                final.append(seg)
        print(final)
        time = "today"
        for item in final:
            if time == "today":
                if item in yesterday:
                    time = "yesterday"
                if item in this_week:
                    time = "this_week"
                if item in last_week:
                    time = "last_week"
                if item in this_month:
                    time = "this_month"
            if item in ac_in_money:
                action = "ac_in_money"
            if item in ac_purchase:
                action = "ac_purchase"
            if item in ac_query:
                action = "ac_query"
            if item in ac_out_money:
                action = "ac_out_money"
            if item in goods:
                nouns = "goods"
            if item in money:
                nouns = "money"
            if item in store:
                nouns = "store"
            if item in price:
                nouns = "price"
            if item in inPrice:
                nouns = "inPrice"
            if item in outPrice:
                nouns = "outPrice"
            if item in supplier:
                nouns = "supplier"
            if item in customer:
                nouns = "customer"
            if item in tables:
                nouns = "tables"
        print(time)
        print(action)
        print(nouns)

        querySell = SellDao()
        queryPurchase = PurchaseDao()
        inputTime = datetime.datetime.strptime(date, '%Y-%m-%d')
        # 对时间进行判断
        if time == "today":
            start = d.replace(year=d.year,
                              month=d.month,
                              day=d.day,
                              hour=0,
                              minute=0,
                              second=0)
            end = d.replace(year=d.year,
                            month=d.month,
                            day=d.day + 1,
                            hour=0,
                            minute=0,
                            second=0)
        if time == "yesterday":
            start = d.replace(year=d.year,
                              month=d.month,
                              day=d.day - 1,
                              hour=0,
                              minute=0,
                              second=0)
            end = d.replace(year=d.year,
                            month=d.month,
                            day=d.day,
                            hour=0,
                            minute=0,
                            second=0)
        if time == "this_week":
            newDay = d.replace(year=d.year,
                               month=d.month,
                               day=d.day,
                               hour=0,
                               minute=0,
                               second=0)
            start = timeProcess.get_current_week(newDay)
            delta = datetime.timedelta(days=7)
            end = start + delta
        if time == "last_week":
            end = timeProcess.get_current_week(d)
            delta = datetime.timedelta(days=7)
            start = end - delta
        if time == "this_month":
            start = d.replace(year=d.year,
                              month=d.month,
                              day=1,
                              hour=0,
                              minute=0,
                              second=0)
            end = d.replace(year=d.year,
                            month=d.month + 1,
                            day=1,
                            hour=0,
                            minute=0,
                            second=0)
        print(time)
        print(start)
        print(end)
        # token = request.headers.get('Authorization')
        token = 'JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1NzI5NTkyOTgsImlhdCI6MTU2Nzc3NTI5OCwiZGF0YSI6eyJhY2NvdW50IjoiMTU4MjcxNTI2NzAiLCJsb2dpbl90aW1lIjoxNTY3Nzc1Mjk4fX0.UqCe-5K99K_HPL8UglxtYUHNLpj_f7rWC3M39SjNRfw'
        headers = {'Authorization': token, 'Content-Type': 'application/json'}
        # 对行为进行判断
        ##### 一段时期内的销售情况 #####
        if action == "ac_in_money" and nouns == "goods":
            data = {"start": start, "end": end, 'companyId': '5', 'date': "hh"}
            data_json = json.dumps(data, cls=DecimalEncoder)
            sellRecords = requests.post(url='http://127.0.0.1:5000/querySell',
                                        data=data_json,
                                        headers=headers)
            SellResult = json.loads(sellRecords.content)
            if SellResult['success'] == True:
                sellResult = SellResult['result']
                print(sellResult)
                groups = []
                goodsType = []
                group = {}
                activeNames = []
                items = []
                for sellRecord in sellResult:
                    item = {}
                    goodsList = sellRecord['goodsList']
                    lists = []
                    content = {}
                    for goods in goodsList:
                        goodsId = goods['goodsId']
                        queryGoodsType = GoodsDao()
                        goodType = queryGoodsType.queryType_byId(goodsId)
                        if goodType[0][0] not in goodsType:
                            goodsType.append(goodType[0][0])
                        list = {}
                        list['title'] = goods['goodsName']
                        list['value'] = goods['number']
                        list['label'] = goods['goodsId']
                        lists.append(list)
                    content['type'] = 'list'
                    content['lists'] = lists
                    item['title'] = sellRecord['date']
                    item['value'] = '顾客' + sellRecord['customerName']
                    item['label'] = sellRecord['id']
                    item['content'] = content
                    items.append(item)
                group['activeNames'] = activeNames
                group['items'] = items
                groups.append(group)
                sellInfo = {
                    'type': 'collapse-group',
                    'summary': '该段时间的销售信息如下:',
                    'groups': groups
                }
                print(json.dumps(sellInfo))
                return json.dumps(sellInfo)
        ##### 某段时间内进的货物 #####
        if action == "ac_purchase" and nouns == "goods":
            data = {'companyId': '5', 'date': "hh", 'start': start, 'end': end}
            data_json = json.dumps(data, cls=DecimalEncoder)
            if time == 'this_month':
                queryForPic = PurchaseDao()
                PicResult = queryForPic.query_ForPic(start, end)
                datas = {}
                datas['type'] = 'line_chart',
                for picData in PicResult:
                    datas[picData[1]] = picData[0]
                print(datas)
            purchaseRecords = requests.post(
                url='http://127.0.0.1:5000/queryPurchase',
                data=data_json,
                headers=headers)
            SellResult = json.loads(purchaseRecords.content)
            print(SellResult)
            if SellResult['success'] == True:
                sellResult = SellResult['result']
                goodsType = []
                print(sellResult)
                groups = []
                group = {}
                activeNames = []
                items = []
                for sellRecord in sellResult:
                    item = {}
                    goodsList = sellRecord['goodsList']
                    lists = []
                    content = {}
                    for goods in goodsList:
                        goodsId = goods['goodsId']
                        queryGoodsType = GoodsDao()
                        goodType = queryGoodsType.queryType_byId(goodsId)
                        if goodType[0][0] not in goodsType:
                            goodsType.append(goodType[0][0])
                        list = {}
                        list['title'] = goods['goodsName']
                        list['value'] = goods['number']

                        list['label'] = goods['goodsId']
                        lists.append(list)
                    content['type'] = 'list'
                    content['lists'] = lists
                    item['title'] = sellRecord['date']
                    item['value'] = '供货商' + sellRecord['supplierName']
                    item['label'] = sellRecord['id']
                    item['content'] = content
                    items.append(item)
                group['activeNames'] = activeNames
                group['items'] = items
                groups.append(group)
                sellInfo = {
                    'type': 'collapse-group',
                    'summary': '该段时间的进货信息如下:',
                    'groups': groups
                }
                print(json.dumps(sellInfo))

                sumPriceByType = []
                sumNumByType = []
                for gType in goodsType:
                    sumOneType = 0
                    sumOneNum = 0
                    for sellRecord in sellResult:
                        goodsList = sellRecord['goodsList']
                        for goods in goodsList:
                            goodsId = goods['goodsId']
                            queryGoodsType = GoodsDao()
                            goodType = queryGoodsType.queryType_byId(goodsId)
                            if goodType[0][0] == gType:
                                sumOneType = sumOneType + goods[
                                    'number'] * goods['price']
                                sumOneNum = sumOneNum + goods['number']
                    sumPriceByType.append(sumOneType)
                    sumNumByType.append(sumOneNum)
                print(goodsType)
                print(sumPriceByType)
                print(sumNumByType)
                return json.dumps(sellInfo)
        ###### 查商品库存#####
        if action == "ac_query" and (nouns == "goods" or nouns == "store"):
            queryWare = WareHouseDao()
            Cusresult = queryWare.query_byCompanyId('5')
            print(Cusresult)
            if len(final) == 3:
                if final[1] in goods:
                    groups = []
                    activeNames = []
                    group = {}
                    items = []
                    for cusresult in Cusresult:
                        item = {}
                        content = {}
                        data = {'companyId': '5', 'wareHouseId': cusresult[0]}
                        data_json = json.dumps(data, cls=DecimalEncoder)
                        goodsStore = requests.post(
                            url='http://127.0.0.1:5000/queryStoreGoods',
                            data=data_json,
                            headers=headers)
                        Goodsstore = json.loads(goodsStore.content)
                        if Goodsstore['success'] == True:
                            goodsResult = Goodsstore['result']
                            goodsList = goodsResult['goodsList']
                            lists = []
                            for goods in goodsList:
                                list = {}
                                list['title'] = goods['name']
                                list['value'] = str(
                                    goods['amount']) + goods['unitInfo']
                                list['label'] = goods['id']
                                lists.append(list)
                        content['type'] = 'list'
                        content[lists] = lists
                        item['content'] = content
                        item['title'] = cusresult[1]
                        item['value'] = cusresult[2]
                        items.append(item)
                    group['items'] = items
                    group['activeNames'] = activeNames
                    groups.append(group)
                    print(groups)
                    storeInfo = {
                        'type': 'collapse-group',
                        'summary': '所有仓库的库存信息如下:',
                        'groups': groups
                    }
                    print(json.dumps(storeInfo))
                    return json.dumps(storeInfo)
                else:
                    data = {'companyId': '5', 'name': final[1]}
                    data_json = json.dumps(data, cls=DecimalEncoder)
                    goodsStore = requests.post(
                        url='http://127.0.0.1:5000/queryStoreGoods',
                        data=data_json,
                        headers=headers)
                    Goodsstore = json.loads(goodsStore.content)
                    if Goodsstore['success'] == True:
                        goodsRecords = Goodsstore['result']
                        queryGoodsResult = goodsRecords['goodsList']
                        print(queryGoodsResult)
                        summary = ""
                        for goodResult in queryGoodsResult:
                            summary = summary + "商品" + goodResult['name'] + "当前库存为:" + str(int(goodResult['amount'])) + \
                                      goodResult['unitInfo'] + '\n'
                        print(summary)
                        storeInfo = {'type': 'text', 'summary': summary}
                        return json.dumps(storeInfo)
                    else:
                        return None
            else:
                data = {'companyId': '5', 'name': final[2]}
                data_json = json.dumps(data, cls=DecimalEncoder)
                goodsStore = requests.post(
                    url='http://127.0.0.1:5000/queryStoreGoods',
                    data=data_json,
                    headers=headers)
                Goodsstore = json.loads(goodsStore.content)
                if Goodsstore['success'] == True:
                    goodsRecords = Goodsstore['result']
                    queryGoodsResult = goodsRecords['goodsList']
                    print(queryGoodsResult)
                    summary = ""
                    for goodResult in queryGoodsResult:
                        summary = summary + "商品" + goodResult['name'] + "当前库存为:" + str(int(goodResult['amount'])) + \
                                  goodResult['unitInfo'] + '\n'
                    print(summary)
                    storeInfo = {'type': 'text', 'summary': summary}
                    return json.dumps(storeInfo)
                else:
                    return None
        # 查询商品的价格
        if action == "ac_query" and (nouns == "price" or nouns == "inPrice"
                                     or nouns == "outPrice"):
            if len(final) == 3:
                data = {'name': final[1]}
            else:
                data = {'name': final[2]}
            data_json = json.dumps(data, cls=DecimalEncoder)
            judge = 0
            allgroups = []
            averageInmoney = 0
            NewInmoney = 0
            averageOutmoney = 0
            NewOutmoney = 0
            if nouns == "price":
                judge = 1
            if nouns == "inPrice" or judge == 1:
                _respIn = requests.post(
                    url='http://127.0.0.1:5000/purchasePriceByName',
                    data=data_json,
                    headers=headers)
                inRecords = json.loads(_respIn.content)
                if inRecords['success'] == True:
                    inRecord = inRecords['result']
                    groups = []
                    group = {}
                    items = []
                    count = 0
                    sumPrice = 0
                    newPrice = 0
                    for inGoods in inRecord:
                        item = {}
                        item['title'] = inGoods['goodName']
                        item['value'] = inGoods['purchasePrice']
                        sumPrice = sumPrice + inGoods['purchasePrice']
                        NewInmoney = newPrice = inGoods['purchasePrice']
                        count = count + 1
                        querySupName = SupplierDao()
                        supID = inGoods['supplierId']
                        querySupNameResult = querySupName.queryName_byId(supID)
                        print(querySupNameResult[0][0])
                        item['label'] = '供货商:' + querySupNameResult[0][0]
                        item['tag'] = inGoods['date']
                        items.append(item)
                    group['title'] = '商品的进价情况如下'
                    group['items'] = items
                    allgroups.append(group)
                    groups.append(group)
                    averageInmoney = round(sumPrice / count, 2)
                    Price = {
                        'type':
                        'list-group',
                        'summary':
                        '商品最新进价为' + str(newPrice) + "元,平均进价为" +
                        str(round(sumPrice / count, 2)) + "元",
                        'groups':
                        groups
                    }
            if nouns == "outPrice" or judge == 1:
                _respOut = requests.post(
                    url='http://127.0.0.1:5000/SellPriceByName',
                    data=data_json,
                    headers=headers)
                inRecords = json.loads(_respOut.content)
                if inRecords['success'] == True:
                    inRecord = inRecords['result']
                    print(inRecord)
                    groups = []
                    group = {}
                    items = []
                    count = 0
                    sumPrice = 0
                    newPrice = 0
                    for inGoods in inRecord:
                        item = {}
                        item['title'] = inGoods['goodsName']
                        item['value'] = str(
                            round(inGoods['sumprice'] / inGoods['number'],
                                  2)) + "元"
                        sumPrice = sumPrice + inGoods['sumprice'] / inGoods[
                            'number']
                        NewOutmoney = newPrice = inGoods['sumprice'] / inGoods[
                            'number']
                        count = count + 1
                        item['label'] = '客户:' + inGoods['customerName']
                        item['tag'] = inGoods['date']
                        items.append(item)
                    group['title'] = '商品的售价情况如下'
                    group['items'] = items
                    groups.append(group)
                    allgroups.append(group)
                    averageOutmoney = round(sumPrice / count, 2)
                    Price = {
                        'type':
                        'list-group',
                        'summary':
                        '商品最新售价为' + str(newPrice) + "元,平均售价为" +
                        str(round(sumPrice / count, 2)) + "元",
                        'groups':
                        groups
                    }
            if nouns == "price":
                Price = {
                    'type':
                    'list-group',
                    'summary':
                    '商品最新售价为' + str(NewOutmoney) + "元,平均售价为" +
                    str(averageOutmoney) + "元 " + ' 商品最新进价为' +
                    str(NewInmoney) + "元,平均进价为" + str(averageInmoney) + "元",
                    'groups':
                    allgroups
                }
            print(Price)
            return json.dumps(Price)

        #### 一段时间的收入或支出####
        if nouns == "money":
            data = {'start': start, 'end': end}
            data_json = json.dumps(data, cls=DecimalEncoder)
            _respCash = requests.post(
                url='http://127.0.0.1:5000/queryCashRecordByDate',
                data=data_json,
                headers=headers)
            CashResult = json.loads(_respCash.content)
            inCash = outCash = 0
            if CashResult['success'] == True:
                cashResult = CashResult['result']
                for sinCash in cashResult:
                    if sinCash['variation'] > 0:
                        inCash = inCash + sinCash['variation']
                    else:
                        outCash = outCash + sinCash['variation']
            _respBank = requests.post(
                url='http://127.0.0.1:5000/queryBankRecordByDate',
                data=data_json,
                headers=headers)
            inBank = outBank = 0
            BankResult = json.loads(_respBank.content)
            if BankResult['success'] == True:
                bankResult = BankResult['result']
                for sinBank in bankResult:
                    if sinBank['amount'] > 0:
                        inBank = inBank + sinBank['amount']
                    else:
                        outBank = outBank + sinBank['amount']
            if action == "ac_in_money":
                summary = '现金收入' + str(inCash) + '元,银行存款、转账等收入' + str(
                    inBank) + '元,共计' + str(inBank + inCash) + '元'
                inMoney = {'type': 'text', 'summary': summary}
                return json.dumps(inMoney)
            if action == "ac_out_money":
                outBank = abs(outBank)
                outCash = abs(outCash)
                summary = '现金支出' + str(outCash) + '元,银行存款、转账等支出' + str(
                    outBank) + '元,共计' + str(outCash + outCash) + '元'
                outMoney = {'type': 'text', 'summary': summary}
                return json.dumps(outMoney)
        #####查询顾客信息#####
        if action == "ac_query" and nouns == "customer":
            name = ''
            print(final[3])
            for i in range(2, len(final) - 1):
                if final[i] != '信息':
                    name = name + final[i]
            print(name)
            data = {'companyId': '5', 'name': name}
            data_json = json.dumps(data, cls=DecimalEncoder)
            _respCustomer = requests.post(
                url='http://127.0.0.1:5000/queryCustomer',
                data=data_json,
                headers=headers)
            CustomerDaoResult = json.loads(_respCustomer.content)
            if CustomerDaoResult['success'] == True:
                customerResult = CustomerDaoResult['result']
                groups = []
                for supplier in customerResult:
                    group = {}
                    items = []
                    for key in supplier:
                        res = {}
                        res['title'] = key
                        res['value'] = supplier[key]
                        items.append(res)
                    group['items'] = items
                    groups.append(group)
                print(groups)
                supplierInfo = {
                    'type': 'list-group',
                    'summary': '客户' + name + '的信息',
                    'groups': groups
                }
                return json.dumps(supplierInfo)
            else:
                return None
            CusResult = _respCash.content
            customerInfo = {
                'type': 'list-group',
                'summary': '客户' + name + '的信息'
            }
            print(CusResult)
        #####查询供应商信息#####
        if action == "ac_query" and nouns == "supplier":
            name = ''
            for i in range(2, len(final) - 1):
                if final[i] != '信息':
                    name = name + final[i]
            print(name)
            data = {'companyId': '5', 'name': name}
            data_json = json.dumps(data, cls=DecimalEncoder)
            _respSupplier = requests.post(
                url='http://127.0.0.1:5000/querySupplierByName',
                data=data_json,
                headers=headers)
            SupplierResult = json.loads(_respSupplier.content)
            if SupplierResult['success'] == True:
                supplierResult = SupplierResult['result']
                groups = []
                for supplier in supplierResult:
                    group = {}
                    items = []
                    for key in supplier:
                        res = {}
                        res['title'] = key
                        res['value'] = supplier[key]
                        items.append(res)
                    group['items'] = items
                    groups.append(group)
                print(groups)
                supplierInfo = {
                    'type': 'list-group',
                    'summary': '供应商' + name + '的信息',
                    'groups': groups
                }
                return json.dumps(supplierInfo)
            else:
                return None
        #####查询表格信息#####
        if action == "ac_query" and nouns == "tables":
            data = {'start': start, 'end': end}
            data_json = json.dumps(data, cls=DecimalEncoder)
            _respCash = requests.post(
                url='http://127.0.0.1:5000/queryCashRecordByDate',
                data=data_json,
                headers=headers)
            CashResult = _respCash.content
            print(CashResult)