tamp_diagnose_app.py 15.9 KB
Newer Older
1
# coding: utf-8
pengxiong's avatar
pengxiong committed
2 3
import datetime

4 5 6 7
from sqlalchemy import Column, DECIMAL, Date, DateTime, Index, String, Table, Text, text
from sqlalchemy.dialects.mysql import BIGINT, INTEGER
from sqlalchemy.ext.declarative import declarative_base

pengxiong's avatar
pengxiong committed
8
from app.api.engine import TAMP_SQL, tamp_user_engine, tamp_diagnose_app_engine, pdf_folder
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
from app.model.base import Base
from app.model.base import BaseModel


class Customer(Base, BaseModel):
    __tablename__ = 'customer'

    id = Column(String(64), primary_key=True, comment='id')
    customer_name = Column(String(64), index=True, comment='客户姓名')
    name = Column(String(64))
    valueSex = Column(INTEGER(11), comment='性别 -- 1.男  2.女')
    valueBirth = Column(DateTime, comment='生日')
    phone = Column(String(20), comment='手机')
    email = Column(String(120), comment='邮箱')
    landline = Column(String(20), comment='座机')
    address = Column(String(120), comment='家庭地址')
    fax = Column(String(20), comment='传真')
    qq = Column(String(20))
    wechat = Column(String(30), comment='微信号')
    wechatNickName = Column(String(30), comment='微信昵称')
    weibo = Column(String(30), comment='微博')
    work = Column(String(50), comment='工作')
    staff = Column(String(50), comment='职务')
    school = Column(String(50), comment='毕业学校')
    nativeplace = Column(String(30), comment='籍贯')
    valueMarry = Column(INTEGER(11), comment='婚姻状况1.未婚 2.已婚 3.离异')
    familyList = Column(String(500), comment='家庭成员')
    favor = Column(String(100), comment='兴趣爱好')
    concatTime = Column(String(30), comment='方便联系时间')
    wealth = Column(String(30), comment='财产')
    extra = Column(String(120))
    total_assets = Column(DECIMAL(22, 6))
    floating_earnings = Column(DECIMAL(22, 6))
    create_by = Column(String(64))
    create_time = Column(DateTime)
    update_by = Column(String(64))
    update_time = Column(DateTime)
    delete_tag = Column(INTEGER(11))
    member_since = Column(DateTime)
    last_seen = Column(DateTime)
    remark = Column(Text, comment='备注')
    group_id = Column(INTEGER(11), index=True, comment='组id')
    company_address = Column(String(200), comment='单位地址')
    other_address = Column(String(200), comment='其他地址')


class CustomerAsset(Base, BaseModel):
    __tablename__ = 'customer_assets'

    id = Column(String(64), primary_key=True, nullable=False, comment='客户id')
    total_market = Column(DECIMAL(22, 6), comment='总市值')
    total_principal = Column(DECIMAL(22, 6), comment='总本金')
    accumulated_earnings = Column(DECIMAL(22, 6), comment='累计收益')
    floating_earnings_proportion = Column(DECIMAL(22, 6), comment='累计收益率')
    delete_tag = Column(INTEGER(11))
    ifa_id = Column(String(64), primary_key=True, nullable=False, comment='理财师id')
    seven_profit_rate = Column(DECIMAL(22, 6), comment='最近7天收益率')
    thirty_profit_rate = Column(DECIMAL(22, 6), comment='最近30天收益率')
    ninety_profit_rate = Column(DECIMAL(22, 6), comment='最近90天收益率')
    half_year_profit_rate = Column(DECIMAL(22, 6), comment='最近半年收益率')
    year_profit_rate = Column(DECIMAL(22, 6), comment='今年收益率')


class FundReportManange(Base, BaseModel):
    __tablename__ = 'fund_report_manange'

    id = Column(String(64), primary_key=True, comment='id')
    ifa_id = Column(String(64), comment='理财师id')
pengxiong's avatar
pengxiong committed
77 78
    default_template = Column(Text, comment='默认模板')
    custom_template = Column(Text, comment='自定义模版')
79 80 81 82 83 84 85
    create_by = Column(String(64))
    create_time = Column(DateTime)
    update_by = Column(String(64))
    update_time = Column(DateTime)
    delete_tag = Column(INTEGER(2), server_default=text("'0'"))
    name = Column(String(300), comment='模版名称')
    type = Column(INTEGER(2), comment='模版类型1持仓报告2诊断报告')
pengxiong's avatar
pengxiong committed
86
    default = Column(INTEGER(2), server_default=text("'0'"))
87

pengxiong's avatar
pengxiong committed
88 89 90 91 92 93 94 95 96 97 98
    def to_dict(self, allow_field=None):
        all_field = [r.name for r in self.__table__.columns]
        if allow_field:
            allow_field = set(allow_field) & set(allow_field)
        else:
            allow_field = all_field
        data = {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field}
        with TAMP_SQL(tamp_user_engine) as tamp_user:
            tamp_user_session = tamp_user.session
            sql = "select ui_username_mp from user_info where id = '{}'".format(self.ifa_id)
            res = tamp_user_session.execute(sql)
pengxiong's avatar
pengxiong committed
99 100 101 102
            if res:
                data['author_name'] = res.fetchone()[0]
            else:
                data['author_name'] = ''
pengxiong's avatar
pengxiong committed
103 104 105 106
        if self.default_template:
            data['sys_default'] = 1
        else:
            data['sys_default'] = 0
pengxiong's avatar
pengxiong committed
107 108
        return data

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

class Group(Base, BaseModel):
    __tablename__ = 'group'
    __table_args__ = (
        Index('describe', 'describe', 'ifauser_id', unique=True),
    )

    id = Column(INTEGER(11), primary_key=True)
    describe = Column(String(50))
    createtime = Column(DateTime)
    ifauser_id = Column(String(64))


class HoldDiagnoseReport(Base, BaseModel):
    __tablename__ = 'hold_diagnose_report'

    id = Column(INTEGER(11), primary_key=True)
    customer_id = Column(String(64))
    ifa_id = Column(String(64))
    update_time = Column(DateTime)
    update_status = Column(INTEGER(11))
    file = Column(String(128))
    be_viewed = Column(INTEGER(2), comment='0未查看1已查看')
pengxiong's avatar
pengxiong committed
132
    report_data = Column(Text)
pengxiong's avatar
pengxiong committed
133 134 135 136 137 138 139 140
    name = Column(String(100))

    def to_dict(self, allow_field=None):
        all_field = [r.name for r in self.__table__.columns]
        if allow_field:
            allow_field = set(allow_field) & set(allow_field)
        else:
            allow_field = all_field
pengxiong's avatar
pengxiong committed
141 142
        if self.file:
            self.file = pdf_folder + self.file
pengxiong's avatar
pengxiong committed
143
        data = {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field}
pengxiong's avatar
pengxiong committed
144
        with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
pengxiong's avatar
pengxiong committed
145
            tamp_user_session = tamp_user.session
pengxiong's avatar
pengxiong committed
146
            tamp_diagnose_app_session = tamp_diagnose_app.session
pengxiong's avatar
pengxiong committed
147 148 149
            sql = "select ui_username_mp from user_info where id = '{}'".format(self.ifa_id)
            res = tamp_user_session.execute(sql)
            sql2 = "select customer_name from tamp_diagnose_app.customer_view where id = '{}'".format(self.customer_id)
pengxiong's avatar
pengxiong committed
150
            res2 = tamp_diagnose_app_session.execute(sql2)
pengxiong's avatar
pengxiong committed
151 152
            res = res.fetchone()
            res2 = res2.fetchone()
pengxiong's avatar
pengxiong committed
153
            if data:
pengxiong's avatar
pengxiong committed
154 155
                if res:
                    data['author_name'] = res[0]
pengxiong's avatar
pengxiong committed
156 157
                else:
                    data['author_name'] = ''
pengxiong's avatar
pengxiong committed
158 159
                if res2:
                    data['customer_name'] = res2[0]
pengxiong's avatar
pengxiong committed
160 161 162
                else:
                    data['customer_name'] = ''
                data['type'] = 2
pengxiong's avatar
pengxiong committed
163
        return data
164 165 166 167 168 169 170 171 172 173 174 175


class HoldReport(Base, BaseModel):
    __tablename__ = 'hold_report'

    id = Column(INTEGER(11), primary_key=True)
    customer_id = Column(String(64))
    ifa_id = Column(String(64))
    update_time = Column(DateTime)
    update_status = Column(INTEGER(11))
    file = Column(String(128))
    be_viewed = Column(INTEGER(2), comment='0未查看1已查看')
pengxiong's avatar
pengxiong committed
176
    report_data = Column(Text)
pengxiong's avatar
pengxiong committed
177 178 179 180 181 182 183 184
    name = Column(String(100))

    def to_dict(self, allow_field=None):
        all_field = [r.name for r in self.__table__.columns]
        if allow_field:
            allow_field = set(allow_field) & set(allow_field)
        else:
            allow_field = all_field
pengxiong's avatar
pengxiong committed
185 186
        if self.file:
            self.file = pdf_folder + self.file
pengxiong's avatar
pengxiong committed
187 188
        data = {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field}
        with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
pengxiong's avatar
pengxiong committed
189
            tamp_user_session = tamp_user.session
pengxiong's avatar
pengxiong committed
190
            tamp_diagnose_app_session = tamp_diagnose_app.session
pengxiong's avatar
pengxiong committed
191 192 193
            sql = "select ui_username_mp from user_info where id = '{}'".format(self.ifa_id)
            res = tamp_user_session.execute(sql)
            sql2 = "select customer_name from tamp_diagnose_app.customer_view where id = '{}'".format(self.customer_id)
pengxiong's avatar
pengxiong committed
194
            res2 = tamp_diagnose_app_session.execute(sql2)
pengxiong's avatar
pengxiong committed
195 196
            res = res.fetchone()
            res2 = res2.fetchone()
pengxiong's avatar
pengxiong committed
197
            if data:
pengxiong's avatar
pengxiong committed
198 199
                if res:
                    data['author_name'] = res[0]
pengxiong's avatar
pengxiong committed
200 201
                else:
                    data['author_name'] = ''
pengxiong's avatar
pengxiong committed
202 203
                if res2:
                    data['customer_name'] = res2[0]
pengxiong's avatar
pengxiong committed
204 205 206
                else:
                    data['customer_name'] = ''
                data['type'] = 1
pengxiong's avatar
pengxiong committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
        return data


class PeriodicReport(Base, BaseModel):
    __tablename__ = 'periodic_report'

    id = Column(INTEGER(11), primary_key=True)
    customer_id = Column(String(64))
    ifa_id = Column(String(64))
    update_time = Column(DateTime)
    update_status = Column(INTEGER(11))
    file = Column(String(128))
    be_viewed = Column(INTEGER(2), comment='0未查看1已查看')
    report_data = Column(Text)
    name = Column(String(100))

    def to_dict(self, allow_field=None):
        all_field = [r.name for r in self.__table__.columns]
        if allow_field:
            allow_field = set(allow_field) & set(allow_field)
        else:
            allow_field = all_field
pengxiong's avatar
pengxiong committed
229 230
        if self.file:
            self.file = pdf_folder + self.file
pengxiong's avatar
pengxiong committed
231 232
        data = {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field}
        with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
pengxiong's avatar
pengxiong committed
233
            tamp_user_session = tamp_user.session
pengxiong's avatar
pengxiong committed
234
            tamp_diagnose_app_session = tamp_diagnose_app.session
pengxiong's avatar
pengxiong committed
235 236 237
            sql = "select ui_username_mp from user_info where id = '{}'".format(self.ifa_id)
            res = tamp_user_session.execute(sql)
            sql2 = "select customer_name from tamp_diagnose_app.customer_view where id = '{}'".format(self.customer_id)
pengxiong's avatar
pengxiong committed
238
            res2 = tamp_diagnose_app_session.execute(sql2)
pengxiong's avatar
pengxiong committed
239 240
            res = res.fetchone()
            res2 = res2.fetchone()
pengxiong's avatar
pengxiong committed
241
            if data:
pengxiong's avatar
pengxiong committed
242 243
                if res:
                    data['author_name'] = res[0]
pengxiong's avatar
pengxiong committed
244 245
                else:
                    data['author_name'] = ''
pengxiong's avatar
pengxiong committed
246 247
                if res2:
                    data['customer_name'] = res2[0]
pengxiong's avatar
pengxiong committed
248 249 250
                else:
                    data['customer_name'] = ''
                data['type'] = 3
pengxiong's avatar
pengxiong committed
251
        return data
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386


class IfaCustomer(Base, BaseModel):
    __tablename__ = 'ifa_customer'

    id = Column(String(64), primary_key=True)
    customer_id = Column(String(64))
    ifa_id = Column(String(64))
    fund_count = Column(INTEGER(11))
    revision = Column(INTEGER(11))
    create_by = Column(String(64))
    create_time = Column(DateTime)
    update_by = Column(String(64))
    update_time = Column(DateTime)
    delete_tag = Column(INTEGER(11))



class IfaFundCollection(Base, BaseModel):
    __tablename__ = 'ifa_fund_collection'
    __table_args__ = (
        Index('unique', 'fund_id', 'ifa_id', 'delete_tag'),
    )

    id = Column(INTEGER(11), primary_key=True, comment='id')
    fund_id = Column(String(64))
    ifa_id = Column(String(64))
    create_time = Column(DateTime)
    create_by = Column(String(255))
    update_time = Column(DateTime)
    update_by = Column(DateTime)
    delete_tag = Column(INTEGER(4), server_default=text("'0'"))
    type = Column(INTEGER(4))


class IfauserFund(Base, BaseModel):
    __tablename__ = 'ifauser_fund'

    id = Column(INTEGER(11), primary_key=True)
    type = Column(INTEGER(11), index=True)
    fund_id = Column(String(30), index=True)
    fund_name = Column(String(30))
    ifauser_id = Column(String(64))
    customer_count = Column(INTEGER(11))
    sum = Column(DECIMAL(22, 6))


class Operation(Base, BaseModel):
    __tablename__ = 'operations'

    id = Column(INTEGER(11), primary_key=True)
    operator_id = Column(String(64), index=True)
    describe = Column(Text)
    timestamp = Column(DateTime, index=True)
    ip = Column(Text)


class RelocateSuggestion(Base, BaseModel):
    __tablename__ = 'relocate_suggestion'

    id = Column(String(64), primary_key=True)
    fund_id = Column(String(64))
    substrategy = Column(INTEGER(11))
    fund_name = Column(String(255))
    percent = Column(DECIMAL(22, 6))
    group_id = Column(String(255))
    delete_tag = Column(INTEGER(11))
    type = Column(INTEGER(11))
    register_number = Column(String(20))


class RelocateSuggestionGroup(Base, BaseModel):
    __tablename__ = 'relocate_suggestion_group'

    id = Column(String(64), primary_key=True)
    group_name = Column(String(255))
    ifa_id = Column(String(255))
    customer_id = Column(String(255))
    create_time = Column(DateTime)
    create_by = Column(String(255))
    update_time = Column(DateTime)
    update_by = Column(String(255))
    delete_tag = Column(INTEGER(11))


class UserHoldFundAsset(Base, BaseModel):
    __tablename__ = 'user_hold_fund_assets'

    id = Column(String(64), primary_key=True)
    reference_market = Column(DECIMAL(22, 6), comment='市值')
    holding_net = Column(DECIMAL(22, 6), comment='累计收益率')
    profit_or_loss = Column(DECIMAL(22, 6), comment='累计收益')
    delete_tag = Column(INTEGER(11))
    annual_profit_rate = Column(DECIMAL(22, 6), comment='年化收益率')
    seven_profit = Column(DECIMAL(22, 6), comment='最近7天收益')
    seven_profit_rate = Column(DECIMAL(22, 6), comment='最近7天收益率')
    seven_annual_profit_rate = Column(DECIMAL(22, 6), comment='最近7天年化收益率')
    thirty_profit = Column(DECIMAL(22, 6), comment='最近30天收益')
    thirty_profit_rate = Column(DECIMAL(22, 6), comment='最近30天收益率')
    thirty_annual_profit_rate = Column(DECIMAL(22, 6), comment='最近30天年化收益率')
    ninety_profit = Column(DECIMAL(22, 6), comment='最近90天收益')
    ninety_profit_rate = Column(DECIMAL(22, 6), comment='最近90天收益率')
    ninety_annual_profit_rate = Column(DECIMAL(22, 6), comment='最近90天年化收益率')
    half_year_profit = Column(DECIMAL(22, 6), comment='最近半年收益')
    half_year_profit_rate = Column(DECIMAL(22, 6), comment='最近半年收益率')
    half_year_annual_profit_rate = Column(DECIMAL(22, 6), comment='最近半年年化收益率')
    year_profit = Column(DECIMAL(22, 6), comment='今年收益')
    year_profit_rate = Column(DECIMAL(22, 6), comment='今年收益率')
    year_annual_profit_rate = Column(DECIMAL(22, 6), comment='今年年化收益率')


class UserHoldFundFromApp(Base, BaseModel):
    __tablename__ = 'user_hold_fund_from_app'

    id = Column(String(64), primary_key=True)
    type = Column(INTEGER(11), index=True, comment='0 公募 1 私募 2 优选')
    fund_id = Column(String(64), index=True)
    fund_name = Column(String(30))
    customer_id = Column(String(64), index=True, comment='customer id')
    subscription_fee = Column(DECIMAL(22, 6), comment='申购费')
    nav = Column(DECIMAL(22, 6), comment='购买时候的净值')
    create_by = Column(String(64))
    create_time = Column(DateTime)
    update_by = Column(String(64))
    update_time = Column(DateTime)
    delete_tag = Column(INTEGER(11))
    confirm_amount = Column(DECIMAL(22, 6), comment='确认金额')
    confirm_share = Column(DECIMAL(22, 6), comment='确认份额')
    order_source = Column(INTEGER(11))
    order_type = Column(INTEGER(1), comment='1、申购或追加 2、赎回 4 暂时其他')
    remark = Column(String(255), comment='订单备注')
    user_id = Column(String(64), index=True, server_default=text("''"), comment='ifa的id')
    folio_name = Column(String(64), comment='组合名称,默认是default')
    confirm_share_date = Column(Date, comment='确认份额日期')
    pay_date = Column(Date, comment='订单支付时间')