Example #1
0
def create_qrcode(name: str = None, owner: str = None, remark: str = None):
    try:
        with transaction():
            record = {
                'name': name,
                'owner': owner,
                'remark': remark,
                'imagename': ''
            }
            qrcodeid = QrCodeDAO.insert(record)
            qrcodeservice.generate_qrcode(qrcodeid=qrcodeid,
                                          imagename='%d.jpg' % qrcodeid)
            QrCodeDAO.update({'imagename': '%d.jpg' % qrcodeid}, id=qrcodeid)

            return str(qrcodeid), 201

    except BusinessException as e:
        logger.exception('创建二维码业务错误')
        return e.msg, e.errcode

    except Exception as e:
        raise RuntimeException('创建二维码异常',
                               extra={'name': name,
                                      'owner': owner,
                                      'remark': remark}) \
            from e
Example #2
0
def createbiz(**kwargs):
    try:
        with transaction():
            bizid = BizDAO.insert({**kwargs})
            return str(bizid), 201

    except Exception as e:
        raise RuntimeException('创建套餐异常',
                               extra={**kwargs}) \
            from e
Example #3
0
def test_transaction(connect):
    connection = Mock(spec=dao.Connection)
    connect.return_value = connection

    with dao.transaction():
        pass

    connect.assert_called_once()
    connection.begin.assert_called_once()
    connection.committrans.assert_called_once()
    connection.rollback.assert_not_called()
Example #4
0
def updatebiz(bizid, **kwargs):
    try:
        with transaction():
            BizDAO.update({**kwargs}, id=bizid)
            return '', 204

    except Exception as e:
        raise RuntimeException('修改套餐异常',
                               extra={'bizid': bizid,
                                      **kwargs}) \
            from e
Example #5
0
def test_transaction_exception(connect):
    connection = Mock(spec=dao.Connection)
    connect.return_value = connection

    with pytest.raises(ValueError):
        with dao.transaction():
            raise ValueError

    connect.assert_called_once()
    connection.begin.assert_called_once()
    connection.committrans.assert_not_called()
    connection.rollback.assert_called_once()
Example #6
0
def createorder(**kwargs):
    try:
        with transaction():
            created_date = datetime_utils.utc8now().date()

            orderid = OrderDAO.insert({'biz': kwargs.get('biz'),
                                       'status': OrderStatus.WAITING.value,
                                       'realname': kwargs.get('realname'),
                                       'nickname': kwargs.get('nickname'),
                                       'headimgurl': kwargs.get('headimgurl'),
                                       'mobile': kwargs.get('mobile'),
                                       'address': kwargs.get('address'),
                                       'lon': kwargs.get('lon'),
                                       'lat': kwargs.get('lat'),
                                       'installtime': kwargs.get('installtime'),
                                       'created_date': created_date.strftime('%Y-%m-%d'),
                                       'source': kwargs.get('source')})

            OrderRecordDAO.insert({'orderid': orderid,
                                   'operation': OrderOperation.CREATE.value,
                                   'opname': kwargs.get('realname')})

            # 获取发送通知的对象
            notifyusersids = set(userservice.get_taged_usersids(tagname=UserTag.ORDERMANAGER.name))
            if kwargs.get('source'):
                qrcode = QrCodeDAO.first_or_default(id=kwargs.get('source'))
                if qrcode:
                    notifyusersids.add(qrcode['owner'])

            tousers = '|'.join(notifyusersids)

            # 发送通知
            order_utils.send_order_notify_message(title='新订单通知',
                                                  message='有新订单了',
                                                  tousers=tousers,
                                                  orderid=orderid,
                                                  realname=kwargs.get('realname'),
                                                  mobile=kwargs.get('mobile'),
                                                  address=kwargs.get('address'),
                                                  operatorname=kwargs.get('operatorname'),
                                                  bizname=kwargs.get('bizname'))

            return str(orderid), 201

    except Exception as e:
        raise RuntimeException('提交订单异常', extra={**kwargs}) from e
Example #7
0
def operateorder(orderid: int, **kwargs):
    try:
        with transaction():
            order = orderservice.get_orderdetail(orderid)

            if order is None:
                return '订单不存在', 400

            operation = kwargs.get('operation')

            handlers = {
                OrderOperation.DISPATCH: _dispatchorder,
                OrderOperation.DEALWITH: _dealwithorder,
                OrderOperation.FINISH: _finishorder,
                OrderOperation.CLOSE: _closeorder
            }

            return handlers[operation](order, **kwargs)

    except Exception as e:
        raise RuntimeException('操作订单异常',
                               extra={'orderid': orderid,
                                      **kwargs}) \
            from e