feat(每月作价):优化住宅售价计算

1. 成交案例下载和清洗
2. 挂牌案例下载、上传、清洗
3. 编写单元测试
This commit is contained in:
purple
2020-06-17 18:39:19 +08:00
parent 517f42edf5
commit 0d14af53ac
35 changed files with 4271 additions and 1 deletions

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.data.cases.mapper.sync.DownloadOriginalResidenceSaleClosingCaseMapper">
<resultMap id="resultMapping" type="com.ruoyi.project.data.cases.domain.OriginalResidenceSaleClosingCase">
<result property="caseCountyName" column="区域"/>
<result property="caseBlockName" column="板块"/>
<result property="caseLoopName" column="环线"/>
<result property="caseCommunityName" column="小区名称"/>
<result property="caseAddress" column="房屋地址"/>
<result property="caseArea" column="面积" javaType="java.math.BigDecimal"/>
<result property="caseHouseType" column="房屋类型"/>
<result property="caseTotalPrice" column="总价" javaType="java.math.BigDecimal"/>
<result property="caseUnitPrice" column="单价" javaType="java.math.BigDecimal"/>
<result property="caseRegisterDate" column="登记日期" javaType="java.sql.Date"/>
<result property="caseSigningDate" column="签约日期" javaType="java.sql.Date"/>
<result property="agencyName" column="中介公司"/>
<result property="agencyType" column="中介类型"/>
<result property="sellerType" column="卖家类型"/>
<result property="buyerType" column="买家类型"/>
<result property="birthday" column="出生年月日" javaType="java.sql.Date"/>
<!-- 成交类型(二手)-->
<result property="cleanCaseType" column="cleanCaseType"/>
</resultMap>
<select id="download" parameterType="int" resultMap="resultMapping">
select
区域
,板块
,环线
,小区名称
,房屋地址
,面积
,房屋类型
,总价
,单价
,登记日期
,签约日期
,中介公司
,中介类型
,卖家类型
,买家类型
,出生年月日
, 2 as cleanCaseType
from dbo.二手房成交数据${yearMonth};
</select>
</mapper>

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.data.cases.mapper.sync.DownloadOriginalResidenceSaleOpeningCaseMapper">
<resultMap id="resultMapping" type="com.ruoyi.project.data.cases.domain.OriginalResidenceSaleOpeningCase">
<result property="caseLianJiaId" column="llid"/>
<result property="caseLianJiaCommunityId" column="lcid"/>
<result property="caseTitle" column="name"/>
<result property="caseApartmentLayout" column="roomtype"/>
<result property="caseArea" column="area" javaType="java.math.BigDecimal"/>
<result property="caseToward" column="towards"/>
<result property="caseStorey" column="storey"/>
<result property="caseLastDeal" column="lastDeal" javaType="java.sql.Date"/>
<result property="caseElevator" column="condoElev"/>
<result property="caseDecoration" column="decoration"/>
<result property="caseYear" column="year"/>
<result property="caseAddress" column="address"/>
<result property="casePrice" column="price" javaType="java.math.BigDecimal"/>
<result property="caseCommunityName" column="cname"/>
<result property="caseVisitedNum" column="visited_num"/>
<result property="caseFirstVisitTime" column="first_visit_time" javaType="java.sql.Date"/>
<result property="caseVisitedNum15" column="visited_num_15"/>
<result property="caseVisitedNum30" column="visited_num_30"/>
<result property="caseUrl" column="url"/>
<result property="caseCommunityUrl" column="curl"/>
<result property="caseGetDate" column="getCaseTime" javaType="java.sql.Date"/>
<result property="caseProvider" column="caseProvider"/>
</resultMap>
<select id="download" resultMap="resultMapping">
select llid
, lcid
, name
, type
, roomtype
, area
, towards
, storey
, lastDeal
, dealToNow
, condoElev
, decoration
, year
, address
, vid
, dataType
, price
, cname
, visited_num
, first_visit_time
, visited_num_15
, visited_num_30
, url
, curl
, getCaseTime
, '链家' as caseProvider
from dbo.Listing_Lianjia;
</select>
</mapper>

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.data.cases.mapper.OriginalResidenceSaleClosingCaseMapper">
<!-- 外部数据重复问题 -->
<update id="createTable">
<bind name="targetTableName" value="'dbo.original_residence_sale_closing_case_' + yearMonth"/>
IF OBJECT_ID(#{targetTableName}, 'U') IS NOT NULL
drop table ${targetTableName};
CREATE TABLE ${targetTableName}
(
id bigint identity (1,1) not null primary key,
case_id varchar(32) not null,
case_county_name nvarchar(20) null,
case_block_name nvarchar(20) null,
case_loopline_name nvarchar(20) null,
case_community_name nvarchar(200) null,
case_address nvarchar(500) not null,
case_area decimal(18, 2) not null,
case_unit_price decimal(18, 2) not null,
case_total_price decimal(18, 2) not null,
case_house_type nvarchar(20) null,
case_signing_date date null,
case_register_date date null,
case_current_floor int null,
case_house_property nvarchar(20) null,
case_apartment_layout nvarchar(20) null,
case_compute_unit_price decimal(18, 2) null,
case_compute_total_price decimal(18, 2) null,
case_ref_unit_price decimal(18, 2) null,
case_ref_total_price decimal(18, 2) null,
case_agency_name nvarchar(200) null,
case_agency_type nvarchar(50) null,
case_seller_type nvarchar(20) null,
case_buyer_type nvarchar(20) null,
case_birthday date null,
case_deal_type int not null,
clean_condo_id nvarchar(20) null,
clean_building_id nvarchar(20) null,
clean_community_id nvarchar(20) null,
clean_condo_address nvarchar(500) null,
clean_property_type nvarchar(20) not null,
create_time datetime not null,
clean_current_floor int null,
clean_building_address nvarchar(200) null
);
</update>
<update id="createCleanTable">
<bind name="targetTableName" value="'dbo.ODS_HOUSINGCASE_DEAL_' + yearMonth"/>
IF OBJECT_ID(#{targetTableName}, 'U') IS NOT NULL
drop table ${targetTableName};
CREATE TABLE ${targetTableName}
(
SID int NOT NULL IDENTITY(1, 1) ,
case_id varchar(32) not null,
ProjectID bigint NULL,
BuildingID bigint NULL,
Area decimal (18, 2) NULL,
UpperFloorSum nvarchar (32) null,
UpperFloorNum nvarchar (32) NULL,
AreaCoff decimal (7, 4) NULL,
FloorCoff decimal (7, 4) NULL,
BuildingCoff decimal (7, 4) NULL,
PriceTotal decimal (18, 2) NOT NULL,
PriceUnit decimal (18, 2) NOT NULL,
PriceUnitAdj decimal (18, 2) NOT NULL,
DateContract date NULL
);
</update>
</mapper>

View File

@ -0,0 +1,168 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.data.cases.mapper.OriginalResidenceSaleOpeningCaseMapper">
<update id="createTable">
<bind name="targetTableName" value="'dbo.original_residence_sale_opening_case_' + yearMonth" />
IF OBJECT_ID(#{targetTableName}, 'U') IS NOT NULL
drop table ${targetTableName};
CREATE TABLE ${targetTableName}
(
case_id varchar (32) NOT NULL,
case_lianjia_id nvarchar (50) NOT null primary key,
case_lianjia_community_id nvarchar (50) NOT NULL,
case_title nvarchar (500) NOT NULL,
clean_property_type nvarchar (20) NULL,
case_apartment_layout nvarchar (500) NOT NULL,
case_house_structure nvarchar (50) NULL,
case_area decimal (10, 2) NOT NULL,
case_underground_area decimal (10, 2) NULL,
case_toward nvarchar (50) NOT NULL,
clean_toward nvarchar (50) NULL,
case_storey nvarchar (20) NOT NULL,
clean_total_floor int NOT NULL,
clean_current_floor_desc nvarchar (20) NULL,
case_elevator nvarchar (20) NULL,
clean_elevator nvarchar (20) NULL,
case_tihu nvarchar (20) NULL,
case_decoration nvarchar (20) NULL,
clean_decoration nvarchar (50) NULL,
case_year int NOT NULL,
clean_year int NOT NULL,
case_address nvarchar (500) NULL,
case_vid nvarchar (500) NULL,
case_chan_quan_xing_zhi nvarchar (200) NULL,
case_price decimal (18, 2) NOT NULL,
clean_unit_price decimal (18, 2) NOT NULL,
clean_total_price decimal (18, 2) NOT NULL,
case_community_name nvarchar (500) NULL,
case_visited_num int NOT NULL,
case_visited_num_15 int NOT NULL,
case_visited_num_30 int NOT NULL,
case_latest_deal_date date NULL,
case_latest_visited_date date NULL,
case_first_visited_date date NULL,
case_url nvarchar (500) NOT NULL,
case_community_url nvarchar (500) NOT NULL,
case_get_date date NOT NULL,
case_provider nvarchar (50) NOT NULL,
uv_community_name nvarchar (500) NULL,
uv_community_address nvarchar (1024) NULL,
uv_community_id nvarchar (20) NULL,
uv_building_id nvarchar (20) NULL,
uv_county nvarchar (50) NULL,
uv_block nvarchar (50) NULL,
uv_loop nvarchar (50) NULL,
area_coefficient decimal (18, 6) NULL,
toward_coefficient decimal (18, 6) NULL,
floor_coefficient decimal (18, 6) NULL,
decoration_coefficient int NULL,
year_coefficient decimal (18, 6) NULL,
building_coefficient decimal (18, 6) NULL,
adjust_unit_price decimal (18, 2) NULL,
clean_project_level nvarchar (50) NULL,
create_time datetime NOT NULL
);
</update>
<update id="createCleanTable">
<bind name="targetTableName" value="'dbo.ODS_HOUSINGCASELISTED_LJ_' + yearMonth" />
IF OBJECT_ID(#{targetTableName}, 'U') IS NOT NULL
drop table ${targetTableName};
CREATE TABLE ${targetTableName}
(
case_id varchar(32) not null,
HouseholdsID_LJ bigint not null primary key,
ProjectID_LJ bigint null,
ProjectID bigint null,
Roomtype nvarchar(64) null,
Area decimal(18, 2) null,
Towards nvarchar(64) null,
UpperFloorSum nvarchar(32) null,
UpperFloorNum nvarchar(32) null,
Elevator tinyint null,
Decoration nvarchar(64) null,
Year int null,
AreaCoff decimal(7, 4) null,
TowardsCoff decimal(7, 4) null,
FloorCoff decimal(7, 4) null,
DecorationRng int null,
YearCoff decimal(7, 4) null,
BuildingCoff decimal(7, 4) null,
PriceTotal decimal(18, 2) null,
PriceUnit decimal(18, 2) not null,
PriceUnitAdj decimal(18, 2) not null,
Visited_Num int null,
First_Visit_Time date null,
Visited_Num_15 int null,
Visited_Num_30 int null,
Status tinyint null,
AdjustedValue decimal(18, 2) null,
AdjustedPst decimal(18, 6) null,
AdjustedCumValue decimal(18, 2) null,
AdjustedCumPst decimal(18, 6) null,
AdjustedCumValueAbs decimal(18, 2) null,
AdjustedCumPstAbs decimal(18, 6) null,
AdjustedCumNum int null,
PriceTotalIn decimal(18, 2) null,
PriceTotalOut decimal(18, 2) null,
PriceDateIn date null,
PriceDateOut date null
);
</update>
<update id="createAssembleTable">
<bind name="targetTableName" value="'dbo.DW_HOUSINGCASE_COMM_' + yearMonth" />
IF OBJECT_ID(#{targetTableName}, 'U') IS NOT NULL
drop table ${targetTableName};
create table ${targetTableName}
(
SID int primary key identity
, case_id varchar(32) not null
, HouseholdsID_LJ bigint
, ProjectID_LJ bigint
, ProjectID bigint --modified
, ProjectName nvarchar(1024)
, ProjectAddr nvarchar(1024)
, County nvarchar(512)
, Block nvarchar(512)
, Loop nvarchar(512)
, Roomtype nvarchar(64)
, Area decimal(18, 2)
, Towards nvarchar(64)
, UpperFloorSum nvarchar(32)
, UpperFloorNum nvarchar(32)
, Elevator tinyint
, Decoration nvarchar(64)
, Year int
, AreaCoff decimal(7, 4)
, TowardsCoff decimal(7, 4)
, FloorCoff decimal(7, 4)
, DecorationRng int
, YearCoff decimal(7, 4)
, BuildingCoff decimal(7, 4)
, BasePrice_1 decimal(18, 2)
, PriceTotal decimal(18, 2) not null
, PriceUnit decimal(18, 2) not null
, PriceUnitAdj decimal(18, 2) not null
, Visited_Num int
, First_Visit_Time date
, Visited_Num_15 int
, Visited_Num_30 int
, Status tinyint
, AdjustedValue decimal(18, 2)
, AdjustedPst decimal(18, 6)
, AdjustedCumValue decimal(18, 2)
, AdjustedCumPst decimal(18, 6)
, AdjustedCumValueAbs decimal(18, 2)
, AdjustedCumPstAbs decimal(18, 6)
, AdjustedCumNum int
, PriceTotalIn decimal(18, 2)
, PriceDateIn date
);
</update>
</mapper>

View File

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.data.cases.mapper.sync.SyncOriginalResidenceSaleOpeningCaseMapper">
<update id="createTable">
<bind name="targetTableName" value="'dbo.ODS_HOUSINGCASELISTED_LJ_' + yearMonth + '_RAW'"/>
IF OBJECT_ID(#{targetTableName}, 'U') IS NULL
CREATE TABLE ${targetTableName}
(
SID int NOT NULL IDENTITY(1, 1) primary key,
llid bigint NULL,
lcid bigint NULL,
Name nvarchar (1024) NULL,
Roomtype nvarchar (50) NULL,
Area decimal (18, 2) NULL,
Towards nvarchar (50) NULL,
Storey nvarchar (50) NULL,
Lastdeal date NULL,
Condoelev nvarchar (50) NULL,
Decoration nvarchar (50) NULL,
Year int NULL,
Address nvarchar (1024) NULL,
Price decimal (18, 2) NULL,
Cname nvarchar (1024) NULL,
Visited_Num int NULL,
First_Visit_Time date NULL,
Visited_Num_15 int NULL,
Visited_Num_30 int NULL,
Url nvarchar (512) NULL,
Curl nvarchar (512) NULL,
CurlDate date NULL
);
truncate table ${targetTableName}
</update>
<insert id="insert" parameterType="com.ruoyi.project.data.cases.domain.OriginalResidenceSaleOpeningCase">
insert into dbo.ODS_HOUSINGCASELISTED_LJ_${yearMonth}_RAW
(
llid
, lcid
, Name
, Roomtype
, Area
, Towards
, Storey
, Lastdeal
, Condoelev
, Decoration
, Year
, Address
, Price
, Cname
, Visited_Num
, First_Visit_Time
, Visited_Num_15
, Visited_Num_30
, Url
, Curl
, CurlDate
) values
(
#{caseLianJiaId},
#{caseLianJiaCommunityId},
#{caseTitle},
#{caseApartmentLayout},
#{caseArea},
#{caseToward},
#{caseStorey},
#{caseLastDeal,jdbcType=DATE},
#{caseElevator},
#{caseDecoration},
#{caseYear},
#{caseAddress},
#{casePrice},
#{caseCommunityName},
#{caseVisitedNum},
#{caseFirstVisitTime,jdbcType=DATE},
#{caseVisitedNum15},
#{caseVisitedNum30},
#{caseUrl},
#{caseCommunityUrl},
#{caseGetDate,jdbcType=DATE}
)
</insert>
</mapper>

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.data.basis.mapper.UVBasePriceMapper">
<!-- <resultMap id="resultMapping" type="com.ruoyi.project.data.basis.domain.UVBasePrice">-->
<!-- -->
<!-- </resultMap>-->
<select id="pageCount"
parameterType="com.ruoyi.project.data.basis.domain.UVBasePriceQueryModel"
resultType="int">
select count(1) from dbo.TLK_基价信息
<where>
<if test="communityId != null">
ITEM_AIRAID=#{communityId}
</if>
<if test="valuePoint != null">
AND ITEM_VALUEPOINT=#{valuePoint}
</if>
<if test="communityType != null">
AND ITEM_PROJECTTYPE=#{communityType}
</if>
<if test="priceType != null">
AND ITEM_PRICETYPE=#{priceType}
</if>
</where>
</select>
<select id="pageList"
parameterType="com.ruoyi.project.data.basis.domain.UVBasePriceQueryModel"
resultType="com.ruoyi.project.data.basis.domain.UVBasePrice">
<!-- <bind name="skip" value=" (pageIndex - 1) * pageSize "></bind>-->
SELECT ITEM_AIRAID as communityId
,ITEM_PROJECTTYPE as communityType
,ITEM_PRICETYPE as priceType
,ITEM_STANDARDPRICE as standardPrice
,ITEM_MAINAREAPRICE as mainAreaPrice
,ITEM_VALUEPOINT as valuePoint
,ITEM_PRICEEXPLAIN as comment
,ITEM_PRICECHG
FROM dbo.TLK_基价信息
<where>
<if test="communityId != null">
ITEM_AIRAID=#{communityId}
</if>
<if test="valuePoint != null">
AND ITEM_VALUEPOINT=#{valuePoint}
</if>
<if test="communityType != null">
AND ITEM_PROJECTTYPE=#{communityType}
</if>
<if test="priceType != null">
AND ITEM_PRICETYPE=#{priceType}
</if>
</where>
order by ITEM_VALUEPOINT desc,ITEM_AIRAID asc offset #{pageIndex} ROW FETCH NEXT #{pageSize} ROWS ONLY;
</select>
</mapper>

View File

@ -0,0 +1,89 @@
--
select t.*, left(addr_floornum,charindex('|', addr_floornum, 1)-1) as ,
substring(addr_floornum, charindex('|', addr_floornum, 1)+1, len(addr_floornum)-charindex('|', addr_floornum, 1)) as "所在层"
into #temp
from (
select a.*, dbo.remove_last_numbers(a.case_address) as addr_floornum
from dbo.original_residence_sale_closing_case_#yearMonth# a
) t;
update #temp set case_county_name=case_county_name+'区';
update #temp set case_county_name='浦东新区' where case_county_name='浦东区';
-- #result
select a.*, b.ID, b.ID,cast(left(case_signing_date,7) as varchar(16)) as
into #result
from #temp a
left join (
select row_number()over(partition by , order by newid()) sq, ID, ID, , from obpm_LianCheng_Data.dbo.AI单套地址20190508
) b
on a.case_county_name = b. and a. = b. and b.sq=1;
update b set b.clean_building_address=a.,
b.clean_current_floor=a.,
b.clean_building_id=a.ID,
b.clean_community_id=a.ID,
b.case_county_name=left(a.case_county_name, 2)
from #result a join dbo.original_residence_sale_closing_case_#yearMonth# b on a.id=b.id
insert into dbo.ODS_HOUSINGCASE_DEAL_#yearMonth#
(
case_id
, ProjectID
, BuildingID
, Area
, UpperFloorSum
, UpperFloorNum
, AreaCoff
, FloorCoff
, BuildingCoff
, PriceTotal
, PriceUnit
, PriceUnitAdj
, DateContract
)
select a.case_id
, a.clean_community_id
, a.clean_building_id
, a.case_area
, b.
, a.clean_current_floor
, d.CoefficientA * a.case_area + d.CoefficientB as AreaCoff
, 1 as FloorCoff
, e.Coefficient as BuildingCoff
, a.case_total_price
, a.case_total_price * 1.0 / a.case_area as PriceUnit
, a.case_total_price * 1.0 / a.case_area / isnull(d.CoefficientA * a.case_area + d.CoefficientB, 1)
/ isnull(e.Coefficient, 1) as PriceUnitAdj
, case_signing_date
from dbo.original_residence_sale_closing_case_#yearMonth# a
left join obpm_LianCheng_Data.dbo.AI楼栋数据_610 b
on a.clean_community_id = b.AI小区ID
and a.clean_building_id = b.AI楼栋ID
left join obpm_LianCheng_Data.dbo.TLK_小区信息管理 c
on a.clean_community_id = c.ITEM_AIRAID and c.ITEM_PROJECTTYPE = '1'
left join obpm_LianCheng_Data.dbo.TLK_字典数据信息 f
on f.ITEM_DICVALUE = c.ITEM_PROPERTYLEVEL and f.ITEM_DICTYPE='物业档次'
left join
(
select ProjectLevel
, LowerKey
, UpperKey
, CoefficientA
, CoefficientB
from obpm_LianCheng_Data.dbo.DIM_PARAMETERS
where CoffType = '面积修正(链家挂牌)'
and ProjectType = '公寓'
) d --
on f.ITEM_DICTEXT = d.ProjectLevel
and
(
a.case_area > d.LowerKey
and a.case_area <= d.UpperKey
)
left join obpm_LianCheng_Data.dbo.DIM_BUILDING_COFF e
on a.clean_building_id = e.BuildingID
where a.case_area > 0 ;

View File

@ -0,0 +1,499 @@
update a
set a.uv_community_id=b.ITEM_ProjectID,
a.uv_building_id=b.ITEM_BuildingID,
a.area_coefficient= D.CoefficientA * A.case_area + D.CoefficientB,
a.toward_coefficient = e.Coefficient,
a.floor_coefficient= f.Coefficient,
a.decoration_coefficient=g.Coefficient,
a.year_coefficient=h.Coefficient,
a.building_coefficient=i.Coefficient,
a.adjust_unit_price = (A.clean_unit_price - isnull(G.Coefficient, 0)) * 1.0 /
isnull(D.CoefficientA * A.case_area + D.CoefficientB, 1) / isnull(E.Coefficient, 1) /
isnull(F.Coefficient, 1) / isnull(H.Coefficient, 1) / isnull(I.Coefficient, 1),
a.clean_project_level = C.PROJECTLEVEL,
a.uv_county=c.countyName,
a.uv_block=c.blockName,
a.uv_loop=c.loopName,
a.uv_community_name=c.ITEM_RANAME,
a.uv_community_address=c.ITEM_RAADRESS
from original_residence_sale_opening_case_#yearMonth# A
left join obpm_LianCheng_Data.dbo.TLK_链家小区 B
on A.case_lianjia_community_id = B.ITEM_ProjectID_LJ
left join
(
select X.ITEM_AIRAID
, y.ITEM_DICTEXT as PROJECTLEVEL
, y2.ITEM_DICTEXT as countyName
, y3.ITEM_DICTEXT as blockName
, y4.ITEM_DICTEXT as loopName
, x.ITEM_RANAME
, x.ITEM_RAADRESS
from obpm_LianCheng_Data.dbo.TLK_小区信息管理 x
left join obpm_LianCheng_Data.dbo.TLK_字典数据信息 y
on x.ITEM_PROPERTYLEVEL = y.ITEM_DICVALUE
left join obpm_LianCheng_Data.dbo.TLK_字典数据信息 y2 -- 区域
on x.ITEM_DISTRICT1 = y2.ITEM_DICVALUE
left join obpm_LianCheng_Data.dbo.TLK_字典数据信息 y3 -- 板块
on x.ITEM_SECTOR121 = y3.ITEM_DICVALUE
left join obpm_LianCheng_Data.dbo.TLK_字典数据信息 y4 -- 环线
on x.ITEM_CIRCLEPOSITION = y4.ITEM_DICVALUE
where X.ITEM_PROJECTTYPE = '1'
and y.ITEM_DICTYPE = '物业档次'
and y2.ITEM_DICTYPE = '区域'
and y3.ITEM_DICTYPE = '板块'
and y4.ITEM_DICTYPE = '环线'
) C
on B.ITEM_ProjectID = C.ITEM_AIRAID
left join
(
select ProjectLevel, LowerKey, UpperKey, Coefficient, CoefficientA, CoefficientB
from obpm_LianCheng_Data.dbo.DIM_PARAMETERS
where CoffType = '面积修正(链家挂牌)'
and ProjectType = '公寓'
) D --
on C.PROJECTLEVEL = D.ProjectLevel
and
(
A.case_area > D.LowerKey
and A.case_area <= D.UpperKey
)
left join
(
select SingleKey, Coefficient
from obpm_LianCheng_Data.dbo.DIM_PARAMETERS
where CoffType = '朝向(链家挂牌)'
and ProjectType = '公寓'
) E --
on A.clean_toward = E.SingleKey
left join
(
select SingleKey, Coefficient, Elevator, UpperKey, LowerKey
from obpm_LianCheng_Data.dbo.DIM_PARAMETERS
where CoffType = '楼层(链家挂牌)'
and ProjectType = '公寓'
) F --
on isnull(A.clean_Elevator, 99) = isnull(F.Elevator, 99)
and A.clean_total_floor = F.UpperKey
and A.clean_current_floor_desc = F.LowerKey
left join
(
select SingleKey, Coefficient
from obpm_LianCheng_Data.dbo.DIM_PARAMETERS
where CoffType = '室内装修(链家挂牌)'
and ProjectType = '公寓'
) G --
on A.clean_Decoration = G.SingleKey
left join
(
select SingleKey, Coefficient
from obpm_LianCheng_Data.dbo.DIM_PARAMETERS
where CoffType = '竣工日期'
and ProjectType = '公寓'
) H --
on A.clean_year = H.SingleKey
left join obpm_LianCheng_Data.dbo.DIM_BUILDING_COFF I
on B.ITEM_BuildingID = I.BuildingID;
----#HousingCaseListAdj 插入挂牌清洗数据
------ 20200312BUG修复朝向处理规则优化
create table #HousingCaseListAdj
(
case_id varchar(32) not null
, HouseholdsID_LJ bigint
, ProjectID_LJ bigint
, Roomtype nvarchar(64)
, Area decimal(18, 2)
, Towards nvarchar(64)
, UpperFloorSum nvarchar(32)
, UpperFloorNum nvarchar(32)
, Elevator tinyint
, Decoration nvarchar(64)
, [Year] int
, PriceTotal decimal(18, 2)
, PriceUnit decimal(18, 2) not null
, Visited_Num int
, First_Visit_Time date
, Visited_Num_15 int
, Visited_Num_30 int
);
insert into #HousingCaseListAdj
(
case_id
, HouseholdsID_LJ
, ProjectID_LJ
, Roomtype
, Area
, Towards
, UpperFloorSum
, UpperFloorNum
, Elevator
, Decoration
, Year
, PriceTotal
, PriceUnit
)
select case_id
, case_lianjia_id
, case_lianjia_community_id
, case_apartment_layout
, case_area
, clean_toward
, clean_total_floor
, clean_current_floor_desc
, clean_elevator
, clean_decoration
, clean_year
, clean_total_price
, clean_unit_price
from original_residence_sale_opening_case_#yearMonth#;
----
create table #HousingCaseListSTD
(
case_id varchar(32) not null
, HouseholdsID_LJ bigint
, ProjectID_LJ bigint
, ProjectID bigint
, BuildingID bigint
, AreaCoff decimal(7, 4)
, TowardsCoff decimal(7, 4)
, FloorCoff decimal(7, 4)
, DecorationRng int
, YearCoff decimal(7, 4)
, BuildingCoff decimal(7, 4)
, PriceUnit decimal(18, 2) not null
, PriceUnitAdj decimal(18, 2) not null
);
insert into #HousingCaseListSTD
(
case_id
, HouseholdsID_LJ
, ProjectID_LJ
, ProjectID
, BuildingID
, AreaCoff
, TowardsCoff
, FloorCoff
, DecorationRng
, YearCoff
, BuildingCoff
, PriceUnit
, PriceUnitAdj
)
select case_id
, case_lianjia_id
, case_lianjia_community_id
, uv_community_id
, uv_building_id
, area_coefficient
, toward_coefficient
, floor_coefficient
, decoration_coefficient
, year_coefficient
, building_coefficient
, clean_unit_price
, adjust_unit_price
from dbo.original_residence_sale_opening_case_#yearMonth#;
--
--- 20200205BUG修复AdjustedValue、AdjustedPst 中当Status=1时值不为0的问题
select
a.case_id,
a.HouseholdsID_LJ,
case when b.Status is null then 3
when a.PriceTotal=b.PriceTotal then 1
else 2 end as Status,
case when a.PriceTotal=b.PriceTotal then 0 -- 20200205修改
when b.Status is null then 0
else a.PriceTotal-b.PriceTotal end AdjustedValue,
case when a.PriceTotal=b.PriceTotal then 0 -- 20200205修改
when b.Status is null then 0
else (a.PriceTotal-b.PriceTotal)*1.0/b.PriceTotal end AdjustedPst,
case when a.PriceTotal=b.PriceTotal then b.AdjustedCumValue
when b.Status is null then 0
else b.AdjustedCumValue + a.PriceTotal-b.PriceTotal end AdjustedCumValue,
case when a.PriceTotal=b.PriceTotal then b.AdjustedCumPst
when b.Status is null then 0
else (b.AdjustedCumValue + a.PriceTotal-b.PriceTotal)*1.0/b.PriceTotalIn end AdjustedCumPst,
case when a.PriceTotal=b.PriceTotal then b.AdjustedCumValueAbs
when b.Status is null then 0
else b.AdjustedCumValueAbs + abs(a.PriceTotal-b.PriceTotal) end AdjustedCumValueAbs,
case when a.PriceTotal=b.PriceTotal then b.AdjustedCumPstAbs
when b.Status is null then 0
else (b.AdjustedCumValueAbs+ abs(a.PriceTotal-b.PriceTotal))*1.0/b.PriceTotalIn end AdjustedCumPstAbs,
case when a.PriceTotal=b.PriceTotal then b.AdjustedCumPstAbs
when b.Status is null then 0
else b.AdjustedCumNum+1 end AdjustedCumNum,
case when b.Status is null then a.PriceTotal else b.PriceTotalIn end PriceTotalIn,
NULL as PriceTotalOut,
case when b.Status is null then getdate() else b.PriceDateIn end PriceDateIn,
cast(NULL as date) as PriceDateOut
into #HousingCaseListStatic
from #HousingCaseListAdj a
left join Ods_HousingCaseListed_LJ_#lastYearMonth# b
on a.HouseholdsID_LJ = b.HouseholdsID_LJ
--()
insert into dbo.ODS_HOUSINGCASELISTED_LJ_#yearMonth#
(
case_id
, HouseholdsID_LJ
, ProjectID_LJ
, ProjectID
, Roomtype
, Area
, Towards
, UpperFloorSum
, UpperFloorNum
, Elevator
, Decoration
, Year
, AreaCoff
, TowardsCoff
, FloorCoff
, DecorationRng
, YearCoff
, BuildingCoff
, PriceTotal
, PriceUnit
, PriceUnitAdj
, Visited_Num
, First_Visit_Time
, Visited_Num_15
, Visited_Num_30
, Status
, AdjustedValue
, AdjustedPst
, AdjustedCumValue
, AdjustedCumPst
, AdjustedCumValueAbs
, AdjustedCumPstAbs
, AdjustedCumNum
, PriceTotalIn
, PriceTotalOut
, PriceDateIn
, PriceDateOut
)
select a.case_id
, a.HouseholdsID_LJ
, a.ProjectID_LJ
, d.ProjectID
, a.Roomtype
, a.Area
, a.Towards
, a.UpperFloorSum
, a.UpperFloorNum
, a.Elevator
, a.Decoration
, a.[Year]
, b.AreaCoff
, b.TowardsCoff
, b.FloorCoff
, b.DecorationRng
, b.YearCoff
, b.BuildingCoff
, a.PriceTotal
, a.PriceUnit
, b.PriceUnitAdj
, a.Visited_Num
, a.First_Visit_Time
, a.Visited_Num_15
, a.Visited_Num_30
, c.Status
, c.AdjustedValue
, c.AdjustedPst
, c.AdjustedCumValue
, c.AdjustedCumPst
, c.AdjustedCumValueAbs
, c.AdjustedCumPstAbs
, c.AdjustedCumNum
, c.PriceTotalIn
, c.PriceTotalOut
, c.PriceDateIn
, c.PriceDateOut
from #HousingCaseListAdj a
left join #HousingCaseListSTD b
on a.HouseholdsID_LJ = b.HouseholdsID_LJ
left join #HousingCaseListStatic c
on a.HouseholdsID_LJ = c.HouseholdsID_LJ
left join DIM_PROJECTID_LJ2AI d
on a.ProjectID_LJ = d.ProjectID_LJ;
/*插入当月下架记录*/
-- #TmpRecordAdd然后插入到当月拍照表记为当月汇总表
insert into dbo.ODS_HOUSINGCASELISTED_LJ_#yearMonth#
(
case_id
, HouseholdsID_LJ
, ProjectID_LJ
, ProjectID
, Roomtype
, Area
, Towards
, UpperFloorSum
, UpperFloorNum
, Elevator
, Decoration
, Year
, AreaCoff
, TowardsCoff
, FloorCoff
, DecorationRng
, YearCoff
, BuildingCoff
, PriceTotal
, PriceUnit
, PriceUnitAdj
, Visited_Num
, First_Visit_Time
, Visited_Num_15
, Visited_Num_30
, Status
, AdjustedValue
, AdjustedPst
, AdjustedCumValue
, AdjustedCumPst
, AdjustedCumValueAbs
, AdjustedCumPstAbs
, AdjustedCumNum
, PriceTotalIn
, PriceTotalOut
, PriceDateIn
, PriceDateOut
)
select a.case_id
, a.HouseholdsID_LJ
, a.ProjectID_LJ
, a.ProjectID
, a.Roomtype
, a.Area
, a.Towards
, a.UpperFloorSum
, a.UpperFloorNum
, a.Elevator
, a.Decoration
, a.[Year]
, a.AreaCoff
, a.TowardsCoff
, a.FloorCoff
, a.DecorationRng
, a.YearCoff
, a.BuildingCoff
, a.PriceTotal
, a.PriceUnit
, a.PriceUnitAdj
, a.Visited_Num
, a.First_Visit_Time
, a.Visited_Num_15
, a.Visited_Num_30
, 4 as Status
, a.AdjustedValue
, a.AdjustedPst
, a.AdjustedCumValue
, a.AdjustedCumPst
, a.AdjustedCumValueAbs
, a.AdjustedCumPstAbs
, a.AdjustedCumNum
, a.PriceTotalIn
, a.PriceTotal as PriceTotalOut
, a.PriceDateIn
, getdate() as PriceDateOut
from ODS_HOUSINGCASELISTED_LJ_#lastYearMonth# a
left join ODS_HOUSINGCASELISTED_LJ_#yearMonth# b
on a.HouseholdsID_LJ = b.HouseholdsID_LJ
where b.HouseholdsID_LJ is null
and a.Status not in ( 4, 5 );
/*插入历史下架记录*/
insert into dbo.ODS_HOUSINGCASELISTED_LJ_#yearMonth#
(
case_id
, HouseholdsID_LJ
, ProjectID_LJ
, ProjectID
, Roomtype
, Area
, Towards
, UpperFloorSum
, UpperFloorNum
, Elevator
, Decoration
, Year
, AreaCoff
, TowardsCoff
, FloorCoff
, DecorationRng
, YearCoff
, BuildingCoff
, PriceTotal
, PriceUnit
, PriceUnitAdj
, Visited_Num
, First_Visit_Time
, Visited_Num_15
, Visited_Num_30
, Status
, AdjustedValue
, AdjustedPst
, AdjustedCumValue
, AdjustedCumPst
, AdjustedCumValueAbs
, AdjustedCumPstAbs
, AdjustedCumNum
, PriceTotalIn
, PriceTotalOut
, PriceDateIn
, PriceDateOut
)
select a.case_id
, a.HouseholdsID_LJ
, a.ProjectID_LJ
, a.ProjectID
, a.Roomtype
, a.Area
, a.Towards
, a.UpperFloorSum
, a.UpperFloorNum
, a.Elevator
, a.Decoration
, a.[Year]
, a.AreaCoff
, a.TowardsCoff
, a.FloorCoff
, a.DecorationRng
, a.YearCoff
, a.BuildingCoff
, a.PriceTotal
, a.PriceUnit
, a.PriceUnitAdj
, a.Visited_Num
, a.First_Visit_Time
, a.Visited_Num_15
, a.Visited_Num_30
, 5 as Status
, a.AdjustedValue
, a.AdjustedPst
, a.AdjustedCumValue
, a.AdjustedCumPst
, a.AdjustedCumValueAbs
, a.AdjustedCumPstAbs
, a.AdjustedCumNum
, a.PriceTotalIn
, a.PriceTotal as PriceTotalOut
, a.PriceDateIn
, a.PriceDateOut
from ODS_HOUSINGCASELISTED_LJ_#lastYearMonth# a
left join ODS_HOUSINGCASELISTED_LJ_#yearMonth# b
on a.HouseholdsID_LJ = b.HouseholdsID_LJ
where b.HouseholdsID_LJ is null
and a.Status in ( 4, 5 );
drop table #HousingCaseListAdj
drop table #HousingCaseListSTD
drop table #HousingCaseListStatic