feature(住宅租赁作价):实现excel导入修改基价

This commit is contained in:
purple 2020-07-01 14:21:41 +08:00
parent fab2701bab
commit 952d2332de
11 changed files with 655 additions and 382 deletions

View File

@ -0,0 +1,8 @@
package com.ruoyi.project.data.cases.service;
public interface IOriginalOfficeCaseService {
/**
* 计算
*/
void compute();
}

View File

@ -0,0 +1,81 @@
package com.ruoyi.project.data.cases.service.impl;
import com.ruoyi.common.utils.LoadUtil;
import com.ruoyi.project.data.cases.domain.OriginalOfficeCase;
import com.ruoyi.project.data.cases.mapper.OriginalOfficeCaseMapper;
import com.ruoyi.project.data.cases.mapper.sync.DownloadOriginalOfficeCaseMapper;
import com.ruoyi.project.data.cases.service.IOriginalOfficeCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Service;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Service
public class OriginalOfficeCaseServiceImpl implements IOriginalOfficeCaseService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Autowired
private DownloadOriginalOfficeCaseMapper downloadOriginalOfficeCaseMapper;
@Autowired
private OriginalOfficeCaseMapper originalOfficeCaseMapper;
/**
* 计算
*/
@Override
// @Scheduled(cron = "")
public void compute() {
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 15);
Date startDate = calendar.getTime();
Integer lastYearMonth = new Integer(String.format("%d%02d", calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH) + 1));
calendar.add(Calendar.MONTH, 1);
Date endDate = calendar.getTime();
Integer yearMonth = new Integer(String.format("%d%02d", calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH) + 1));
before(yearMonth, startDate, endDate);
running(yearMonth, lastYearMonth);
}
/**
* 创建表
*
* @param yearMonth
*/
private void before(Integer yearMonth, Date startDate, Date endDate) {
// 创建表
originalOfficeCaseMapper.createTable(yearMonth);
originalOfficeCaseMapper.createArtificialTable(yearMonth);
// 下载列表
List<OriginalOfficeCase> downloadList = downloadOriginalOfficeCaseMapper.download(startDate, endDate);
SqlParameterSource[] batchParams = SqlParameterSourceUtils.createBatch(downloadList.toArray());
namedParameterJdbcTemplate.batchUpdate("insert into dbo.ODS_OFFICECASELISTED_" + yearMonth.toString() + "_RAW" +
"(url, title,容积率,总价售,均价售, 楼盘名称, 楼盘名称_M, 楼层, 面积, 物业费, 工位数, 地址, 地铁, 发布时间, 房源编号, 百度lng, 百度lat, 区域, 分类, " +
"来源, 等级, 楼盘网址, 装修,类型, 板块, 挂牌中介, 月租金租, 标准租金租, 得房率, 总价, 单价) values(:url,:title,:floorAreaRatio," +
":caseTotalPrice," +
":caseUnitPrice,:name,:name_m,:caseFloor,:area,:managementFee,:seatCount,:address,:metro," +
":publishDate,:sourceNo,:lng,:lat,:county,:catalog,:source,:level,:homePageUrl,:decoration," +
":type,:block,:agency,:rentOfMonthly,:rentOfStandard,:score,:totalPrice,:unitPrice) ", batchParams);
}
private void running(Integer yearMonth, Integer lastYearMonth) {
String rawSql = LoadUtil.loadContent("sql-template/compute_office_price.sql");
String sql = rawSql.replace("#yearMonth#", yearMonth.toString())
.replace("#lastYearMonth#", lastYearMonth.toString());
jdbcTemplate.execute(sql);
}
}

View File

@ -94,7 +94,7 @@ public class ResidenceRentBasePriceController extends BaseController {
List<ComputeResidenceRentBasePrice> list =
computeResidenceRentPriceService.selectPageList(computeResidenceRentBasePrice);
ExcelUtil<ComputeResidenceRentBasePrice> util = new ExcelUtil<>(ComputeResidenceRentBasePrice.class);
return util.exportExcel(list, "住宅租赁基价");
return util.exportExcel(list, "住宅租赁基价初始化-" + computeResidenceRentBasePrice.getYearMonth());
}

View File

@ -54,12 +54,6 @@ public interface IUltimateOfficeBasePriceService {
*/
List<VueSelectModel> getYearMonthList();
/**
* 计算
*/
void compute();
}

View File

@ -4,6 +4,7 @@ import com.baomidou.dynamic.datasource.annotation.DS;
import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement;
import com.microsoft.sqlserver.jdbc.SQLServerDataTable;
import com.microsoft.sqlserver.jdbc.SQLServerException;
import com.ruoyi.common.utils.LoadUtil;
import com.ruoyi.project.common.VueSelectModel;
import com.ruoyi.project.data.price.domain.ArtificialResidenceRentBasePrice;
import com.ruoyi.project.data.price.domain.ArtificialResidenceSaleBasePrice;
@ -14,10 +15,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@ -39,6 +42,9 @@ public class ArtificialResidenceRentPriceServiceImpl implements IArtificialResid
@Autowired
private ArtificialResidenceRentPriceMapper artificialResidenceRentPriceMapper;
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public ArtificialResidenceRentBasePrice selectById(Integer yearMonth, String id) {
ArtificialResidenceRentBasePrice residenceRentBasePrice =
@ -94,6 +100,10 @@ public class ArtificialResidenceRentPriceServiceImpl implements IArtificialResid
Date valuePoint = calendar.getTime();
calendar.add(Calendar.MONTH, -1);
Date lastValuePoint = calendar.getTime();
String lastYearMonth = String.format("%d%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String priceDate = simpleDateFormat.format(valuePoint);
String lastPriceDate = simpleDateFormat.format(lastValuePoint);
artificialResidenceRentPriceMapper.prepareBachImport(yearMonth);
CopyOnWriteArrayList<ArtificialResidenceRentBasePrice> copyOnWriteArrayList = new CopyOnWriteArrayList<>();
@ -162,6 +172,14 @@ public class ArtificialResidenceRentPriceServiceImpl implements IArtificialResid
// 删除存储过程还原环境
statement.execute("drop procedure BatchImportOfArtificialResidenceRent");
conn.close();
// 人工修正导入
// yearMonth, lastYearMonth, lastPriceDate, priceDate
String rawSql = LoadUtil.loadContent("sql-template/update_rent_price.sql");
String sql = rawSql.replace("#yearMonth#", yearMonth.toString())
.replace("#lastYearMonth#", lastYearMonth)
.replace("#priceDate#", priceDate)
.replace("#lastPriceDate#", lastPriceDate);
jdbcTemplate.update(sql);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -11,7 +11,6 @@ import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.config.UVConfig;
import com.ruoyi.project.common.UVResponse;
import com.ruoyi.project.common.VueSelectModel;
import com.ruoyi.project.data.cases.domain.OriginalOfficeCase;
import com.ruoyi.project.data.cases.mapper.OriginalOfficeCaseMapper;
import com.ruoyi.project.data.cases.mapper.sync.DownloadOriginalOfficeCaseMapper;
import com.ruoyi.project.data.price.domain.OfficeBasePriceModifyModel;
@ -40,21 +39,12 @@ import org.springframework.web.client.RestTemplate;
@DS("compute")
public class UltimateOfficeBasePriceServiceImpl implements IUltimateOfficeBasePriceService {
private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
private static final Logger log = LoggerFactory.getLogger(UltimateOfficeBasePriceServiceImpl.class);
@Autowired
private UltimateOfficeBasePriceMapper officeBasePriceUltimateMapper;
@Autowired
private UVConfig uvConfig;
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Autowired
private DownloadOriginalOfficeCaseMapper downloadOriginalOfficeCaseMapper;
@Autowired
private OriginalOfficeCaseMapper originalOfficeCaseMapper;
private static Integer getLastYearMonth(Integer yearMonth) {
Calendar calendar = Calendar.getInstance();
@ -250,61 +240,4 @@ public class UltimateOfficeBasePriceServiceImpl implements IUltimateOfficeBasePr
return officeBasePriceModifyModel;
}
/**
* 计算
*/
@Override
// @Scheduled(cron = "")
public void compute() {
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 15);
Date startDate = calendar.getTime();
Integer lastYearMonth = new Integer(String.format("%d%02d", calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH) + 1));
calendar.add(Calendar.MONTH, 1);
Date endDate = calendar.getTime();
Integer yearMonth = new Integer(String.format("%d%02d", calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH) + 1));
before(yearMonth, startDate, endDate);
running(yearMonth, lastYearMonth);
}
/**
* 创建表
*
* @param yearMonth
*/
private void before(Integer yearMonth, Date startDate, Date endDate) {
// 创建表
originalOfficeCaseMapper.createTable(yearMonth);
originalOfficeCaseMapper.createArtificialTable(yearMonth);
// 下载列表
List<OriginalOfficeCase> downloadList = downloadOriginalOfficeCaseMapper.download(startDate, endDate);
SqlParameterSource[] batchParams = SqlParameterSourceUtils.createBatch(downloadList.toArray());
namedParameterJdbcTemplate.batchUpdate("insert into dbo.ODS_OFFICECASELISTED_" + yearMonth.toString() + "_RAW" +
"(url, title,容积率,总价售,均价售, 楼盘名称, 楼盘名称_M, 楼层, 面积, 物业费, 工位数, 地址, 地铁, 发布时间, 房源编号, 百度lng, 百度lat, 区域, 分类, " +
"来源, 等级, 楼盘网址, 装修,类型, 板块, 挂牌中介, 月租金租, 标准租金租, 得房率, 总价, 单价) values(:url,:title,:floorAreaRatio," +
":caseTotalPrice," +
":caseUnitPrice,:name,:name_m,:caseFloor,:area,:managementFee,:seatCount,:address,:metro," +
":publishDate,:sourceNo,:lng,:lat,:county,:catalog,:source,:level,:homePageUrl,:decoration," +
":type,:block,:agency,:rentOfMonthly,:rentOfStandard,:score,:totalPrice,:unitPrice) ", batchParams);
}
private void running(Integer yearMonth, Integer lastYearMonth) {
String rawSql = LoadUtil.loadContent("sql-template/compute_office_price.sql");
String sql = rawSql.replace("#yearMonth#", yearMonth.toString())
.replace("#lastYearMonth#", lastYearMonth.toString());
jdbcTemplate.execute(sql);
}
private void after() {
}
}

View File

@ -22,7 +22,7 @@
<result property="projectLevel" column="projectLevel"/>
<result property="propertyDevPeriod" column="propertyDevPeriod"/>
<result property="bindClassID" column="bindClassID"/>
<result property="mainCoefficientRent" column="mainCoffRent"/>
<result property="mainCoefficientRent" column="mainCoff_Rent"/>
<result property="rentPriceDft" column="rentPriceDft"/>
<result property="mainRentPriceDft" column="mainRentPriceDft"/>
<result property="rentPrice_1" column="rentPrice_1"/>

View File

@ -53,40 +53,24 @@
CREATE TABLE ${targetTableName}
(
id uniqueidentifier not null,
BuildingID bigint NOT NULL,
UnifiedID bigint NULL,
ProjectID bigint NOT NULL,
BuildingID_P nvarchar (20) NOT NULL,
ProjectID_P bigint NULL,
MainPrice decimal (38, 6) NULL,
MainPriceRent decimal (38, 6) NULL,
MainPricePst decimal (38, 6) NULL,
MainPriceRentPst decimal (38, 6) NULL,
MainPriceType varchar (2) NULL,
MainPriceRentType varchar (2) NULL,
ModifyDate date NULL,
Status nvarchar (30) NULL,
BuildingStd tinyint NULL,
AdjEvd nvarchar (1000) NULL,
MainPrice_1 decimal (38, 6) NULL,
MainPriceRent_1 decimal (38, 6) NULL,
AreaCoff decimal (7, 4) NULL,
YearCoff decimal (7, 4) NULL,
BuildingCoff decimal (7, 4) NULL,
ProjectName nvarchar (1024) NULL,
ProjectAddr nvarchar (1024) NULL,
BuildingAddr nvarchar (1024) NULL,
ProjectID bigint NULL,
County nvarchar (512) NULL,
Loop nvarchar (512) NULL,
Block nvarchar (512) NULL,
Street nvarchar (512) NULL,
ProjectAddr nvarchar (1024) NULL,
ProjectName nvarchar (1024) NULL,
Year int NULL,
AvgArea decimal (18, 2) NULL,
TotalFloorSum nvarchar (32) NULL,
UpperFloorSum nvarchar (32) NULL,
OfficeClass nvarchar (256) NULL,
Grade nvarchar (64) NULL
Grade nvarchar (64) NULL,
MainPrice_1 decimal (18, 2) NULL,
MainPriceRent_1 decimal (18, 2) NULL,
MainPrice decimal (18, 2) NULL,
MainPriceRent decimal (18, 2) NULL,
ModifyDate date NULL
);
</update>
</mapper>

View File

@ -245,72 +245,57 @@
);
</update>
<!-- 人工修正价格和作价表一摸一样 -->
<!-- 人工修正-->
<update id="createArtificialPriceTable">
<bind name="targetTableName" value="'dbo.DWA_PROJECTBASEPRICE_MANU_' + yearMonth" />
<bind name="targetTableName" value="'dbo.DWA_PROJECTBASEPRICE_RENT_MANU_' + yearMonth"/>
IF OBJECT_ID(#{targetTableName}, 'U') IS NOT NULL
drop table ${targetTableName};
create table ${targetTableName}
(
SID int not null identity(1,1)
, ProjectID nvarchar(20) primary key
, ProjectName nvarchar(1024)
, ProjectAddr nvarchar(1024)
, County nvarchar(512)
, Block nvarchar(512)
, Loop nvarchar(512)
, IsIndxGen tinyint
, IsPstCalc tinyint
, StatusRun tinyint
, ProjectSPLabel nvarchar(64)
, PropertyType nvarchar(256)
, ProjectType nvarchar(256)
, ProjectTypeDtl nvarchar(256)
, ProjectLevel nvarchar(64)
, Year int
, MainArea decimal(18, 2)
, AreaCoff decimal(7, 4)
, YearCoff decimal(7, 4)
, PriceNote nvarchar(1024)
, BasePriceDft decimal(18, 2)
, MainPriceDft decimal(18, 2)
, BasePrice_1 decimal(18, 2)
, PriceUnitAdj decimal(18, 2)
, Visited_Num int
, First_Visit_Time date
, Visited_Num_15 int
, Visited_Num_30 int
, PriceDealMean_1 decimal(18, 2)
, PriceDealMax_1 decimal(18, 2)
, SumDeal_1 int
, PriceDealMean decimal(18, 2)
, PriceDealMax decimal(18, 2)
, SumDeal int
, PriceListedMin decimal(18, 2)
, PriceCase1_ToAI_Pst decimal(18, 6)
, PriceCase2_ToAI_Pst decimal(18, 6)
, PriceCase1_ToLst_Pst decimal(18, 6)
, PriceCase2_ToLst_Pst decimal(18, 6)
, PriceCase1 decimal(18, 2)
, PriceCase1AdjPst decimal(18, 6)
, SumCase1 int
, PriceCase2 decimal(18, 2)
, PriceCase2AdjPst decimal(18, 6)
, SumCase2 int
, VOPPBT varchar(64)
, VOPPB decimal(18, 6)
, BindProjID int
, Bind_Proj_Pst decimal(18, 6)
, Bind_Block_Class nvarchar(128)
, Bind_Block_Class_Pst decimal(18, 6)
, Bind_Block_Plevel nvarchar(128)
, Bind_Block_Plevel_Pst decimal(18, 6)
, Bind_Block_PType nvarchar(128)
, Bind_Block_Ptype_Pst decimal(18, 6)
, Bind_County_PType nvarchar(128)
, Bind_County_Ptype_Pst decimal(18, 6)
id uniqueidentifier not null
, ProjectID bigint primary key
, MainCoff_Rent decimal(7, 4)
, RentPrice decimal(18, 2)
, MainRentPrice decimal(18, 2)
, RentPrice_1 decimal(18, 2)
, VOPPAT varchar(64)
, VOPPA decimal(18, 6)
, ModifyDate date
);
</update>
<!-- 核准住宅租赁基价 -->
<update id="createUltimateTable">
<bind name="targetTableName" value="'dbo.ODS_PROJECT_RENT_PRICE_INFO_' + yearMonth"/>
IF OBJECT_ID(#{targetTableName}, 'U') IS NOT NULL
drop table ${targetTableName};
create table ODS_PROJECT_RENT_PRICE_INFO_202007
(
id uniqueidentifier primary key
, ProjectID bigint not null
, PriceType int
, BasePrice_1 decimal(18, 2)
, RentPrice decimal(18, 2)
, SumCase1 int
, VOPPAT varchar(64)
, VOPPA decimal(18, 6)
, GF_1Room decimal(18, 2)
, GF_2Room decimal(18, 2)
, GY_2Room decimal(18, 2)
, GY_3Room decimal(18, 2)
, One_Room decimal(18, 2)
, Two_Room decimal(18, 2)
, Three_Room decimal(18, 2)
, EntireRentRatio decimal(18, 4)
, EntireRentNum int
, ShareRentRatio decimal(18, 4)
, ShareRentNum int
, SaleRentRatio decimal(18, 4)
, ModifyDate date
, Status bit
, AdjEvd nvarchar(1024)
);
</update>
</mapper>

View File

@ -212,7 +212,8 @@
<insert id="insertArtificialOfficeBasePrice"
parameterType="com.ruoyi.project.data.price.domain.UltimateOfficeBasePrice">
insert into
dbo.DWA_PROJECTBASEPRICE_OFFICE_MANU_${yearMonth}(ID,BuildingID,ProjectID,County,"Loop",Block,ProjectAddr,ProjectName,Year,AvgArea,TotalFloorSum,UpperFloorSum,OfficeClass,Grade,MainPrice_1,MainPriceRent_1,MainPrice,MainPriceRent,ModifyDate) values(#{id},#{buildingId},#{communityId},#{countyName},#{loopName},#{blockName},#{communityAddress},#{communityName},#{year},#{avgArea},#{totalFloorSum},#{upperFloorSum},#{officeClass},#{officeLevel},#{mainPrice_1},#{mainPriceRent_1},#{mainPrice},#{mainPriceRent},getdate())
dbo.DWA_PROJECTBASEPRICE_OFFICE_MANU_${yearMonth}(ID,BuildingID,ProjectID,County,"Loop",Block,ProjectAddr,ProjectName,Year,AvgArea,TotalFloorSum,UpperFloorSum,OfficeClass,Grade,MainPrice_1,MainPriceRent_1,MainPrice,MainPriceRent,ModifyDate)
values(#{id},#{buildingId},#{communityId},#{countyName},#{loopName},#{blockName},#{communityAddress},#{communityName},#{year},#{avgArea},#{totalFloorSum},#{upperFloorSum},#{officeClass},#{officeLevel},#{mainPrice_1},#{mainPriceRent_1},#{mainPrice},#{mainPriceRent},getdate())
</insert>
<!-- 更新状态 -->
<update id="updateStatus">

View File

@ -0,0 +1,269 @@
/***********************小区租金价格计算************************/
WITH STP AS(
SELECT A.ProjectID, 2 AS PriceType, B.BasePrice AS BasePrice_1, A.RentPriceDft as RentPrice, A.MainRentPriceDft as MainRentPrice,
A.SumCase1, A.VOPPAT, A.VOPPA,
CASE WHEN C.ProjectLevel = '工房1' THEN A.RentPriceDft*(1+24*0.012)*1.0/(1.0*(1+0.011*1.8))
WHEN C.ProjectLevel = '工房2' THEN A.RentPriceDft*(1+26*0.012)*1.0/(1.0*(1+0.011*1.8))
END AS GF_1Room,
CASE WHEN C.ProjectLevel = '工房1' THEN A.RentPriceDft*(1+16*0.012)*1.0/(1.0*(1+0.011*1.8))
WHEN C.ProjectLevel = '工房2' THEN A.RentPriceDft*(1+16*0.012)*1.0/(1.0*(1+0.011*1.8))
END AS GF_2Room,
CASE WHEN C.ProjectLevel = '低端公寓1' THEN A.RentPriceDft*1.0*(1+0.011*3.3)/(1.0*(1+0.011*1.8))
WHEN C.ProjectLevel IN ('中端公寓','低端公寓2') THEN A.RentPriceDft*1.0*(1+0.011*3.3)/(1.0*(1+0.011*1.8))
WHEN C.ProjectLevel IN ('高端公寓','超高端公寓') THEN A.RentPriceDft*(1+5*0.012)*(1+0.011*3.3)/((1.0+0.011*1.8))
END AS GY_2Room,
CASE WHEN C.ProjectLevel = '低端公寓1' THEN A.RentPriceDft*(1-3*0.012)*(1+0.011*4.25)/(1*(1+0.011*1.8))
WHEN C.ProjectLevel = '低端公寓2' THEN A.RentPriceDft*(1-4*0.012)*(1+0.011*4.25)/(1*(1+0.011*1.8))
WHEN C.ProjectLevel = '中端公寓' THEN A.RentPriceDft*(1-3*0.012)*(1+0.011*4.25)/(1*(1+0.011*1.8))
WHEN C.ProjectLevel IN ('高端公寓','超高端公寓') THEN A.RentPriceDft*(1+4*0.012)*(1+0.011*4.25)/((1+0.011*1.8))
END AS GY_3Room
FROM DWA_PROJECTBASEPRICE_RENT_IMDT_#yearMonth# A
LEFT JOIN ODS_PROJECT_PRICE_INFO_#lastYearMonth# B
ON A.ProjectID = B.ProjectID AND B.STATUS = 1
LEFT JOIN ResidenceCommunity C
ON A.ProjectID = C.CommunityId;
)
INSERT INTO ODS_PROJECT_RENT_PRICE_INFO_#yearMonth#
SELECT A.ProjectID, A.PriceType, A.BasePrice_1, A.RentPrice, A.SumCase1, A.VOPPAT, A.VOPPA, A.GF_1Room, A.GF_2Room, A.GY_2Room, A.GY_3Room,
A.GF_1Room*35 AS One_Room,
CASE WHEN A.GF_2Room IS NOT NULL THEN A.GF_2Room*50 ELSE GY_2Room*90 END AS Two_Room,
A.GY_3Room*105 AS Three_Three_Room, B.EntireRentRatio, B.EntireRentNum,
B.ShareRentRatio, B.ShareRentNum, A.RentPrice*12/A.BasePrice_1 AS SaleRentRatio, CONVERT(DATE,NULL) AS ModifyDate,
1 AS Status, NULL AdjEvd
FROM STP A
LEFT JOIN (
SELECT ProjectID,
AVG(CASE WHEN RangeFlag = 30 THEN EntireRentRatio END) AS EntireRentRatio,
SUM(CASE WHEN RangeFlag = 30 THEN 1 END) AS EntireRentNum,
AVG(CASE WHEN RangeFlag = 40 THEN ShareRentRatio END) AS ShareRentRatio,
SUM(CASE WHEN RangeFlag = 40 THEN 1 END) AS ShareRentNum
FROM DW_HOUSINGCASE_RENT_COMM_#yearMonth#
GROUP BY ProjectID
) B ON A.ProjectID = B.ProjectID;
drop table #InfoChg;
drop table #InfoChgCurr;
---
select a.ProjectID, a.RentPrice, a.RentPrice_1, a.VOPPAT, a.VOPPA, GETDATE() AS ModifyDate,
case when b.ProjectID is not null and isnull(a.RentPrice,0) <> isnull(b.RentPrice,0) then 1 else 0 end as RentPriceChg,
case when b.ProjectID is not null and isnull(a.VOPPAT,'') <> isnull(b.VOPPAT,'') then 1 else 0 end as VOPPATChg, -- 指当期价格涨跌幅类型字段变化
case when b.ProjectID is not null and isnull(a.VOPPA,0) <> isnull(b.VOPPA,0) then 1 else 0 end as VOPPAChg, -- 指当期价格涨跌幅字段变化
case when c.ProjectID is not null then 1 else 0 end as RentPrice_1Chg
into #InfoChg
from DWA_PROJECTBASEPRICE_RENT_MANU_#yearMonth# a
left join ODS_PROJECT_RENT_PRICE_INFO_#yearMonth# b
on a.ProjectID = b.ProjectID and b.status=1 and (
isnull(a.RentPrice,0) <> isnull(b.RentPrice,0) or
isnull(a.VOPPAT,'') <> isnull(b.VOPPAT,'') or
isnull(a.VOPPA,0) <> isnull(b.VOPPA,0))
left join ODS_PROJECT_RENT_PRICE_INFO_#lastYearMonth# c
on a.ProjectID = c.ProjectID and c.status=1 and isnull(a.RentPrice_1,0) <> isnull(c.RentPrice,0)
where b.ProjectID is not null or c.ProjectID is not null;
----
select a.ProjectID, a.PriceType, a.BasePrice_1, b.RentPrice, a.SumCase1, b.VOPPAT, b.VOPPA,
a.GF_1Room*b.RentPrice/a.RentPrice as GF_1Room,
a.GF_2Room*b.RentPrice/a.RentPrice as GF_2Room,
a.GY_2Room*b.RentPrice/a.RentPrice as GY_2Room,
a.GY_3Room*b.RentPrice/a.RentPrice as GY_3Room,
a.One_Room*b.RentPrice/a.RentPrice as One_Room,
a.Two_Room*b.RentPrice/a.RentPrice as Two_Room,
a.Three_Room*b.RentPrice/a.RentPrice as Three_Room,
a.EntireRentRatio*b.RentPrice/a.RentPrice as EntireRentRatio,
a.EntireRentNum,
a.ShareRentRatio*b.RentPrice/a.RentPrice as ShareRentRatio,
a.ShareRentNum,
a.SaleRentRatio*b.RentPrice/a.RentPrice as SaleRentRatio,
b.ModifyDate, 1 as Status,
case when RentPriceChg=0 then '' else 'RentPriceChg|' end +
case when VOPPATChg=0 then '' else 'VOPPATChg|' end +
case when VOPPAChg=0 then '' else 'VOPPAChg|' end as AdjEvd
into #InfoChgCurr
from ODS_PROJECT_RENT_PRICE_INFO_#yearMonth# a
inner join #InfoChg b
on a.ProjectID = b.ProjectID
where (b.RentPriceChg=1 or b.VOPPATChg=1 or b.VOPPAChg=1) and a.status=1;
update a
set a.Status = 0
from ODS_PROJECT_RENT_PRICE_INFO_#yearMonth# a
left join #InfoChgCurr b
on a.ProjectID = b.ProjectID
where b.ProjectID is not null and a.status=1;
insert into ODS_PROJECT_RENT_PRICE_INFO_#yearMonth#
select * from #InfoChgCurr
----
-----BUG修复使
-----
select a.ProjectID, a.PriceType, a.BasePrice_1, b.RentPrice_1, a.SumCase1, a.VOPPAT, a.VOPPA,
a.GF_1Room*b.RentPrice_1/a.RentPrice as GF_1Room,
a.GF_2Room*b.RentPrice_1/a.RentPrice as GF_2Room,
a.GY_2Room*b.RentPrice_1/a.RentPrice as GY_2Room,
a.GY_3Room*b.RentPrice_1/a.RentPrice as GY_3Room,
a.One_Room*b.RentPrice_1/a.RentPrice as One_Room,
a.Two_Room*b.RentPrice_1/a.RentPrice as Two_Room,
a.Three_Room*b.RentPrice_1/a.RentPrice as Three_Room,
a.EntireRentRatio*b.RentPrice_1/a.RentPrice as EntireRentRatio,
a.EntireRentNum,
a.ShareRentRatio*b.RentPrice_1/a.RentPrice as ShareRentRatio,
a.ShareRentNum,
a.SaleRentRatio*b.RentPrice_1/a.RentPrice as SaleRentRatio,
b.ModifyDate, 1 as Status,
'RentPrice_1Chg|' as AdjEvd
into #InfoChgLst
from ODS_PROJECT_RENT_PRICE_INFO_#lastYearMonth# a
inner join #InfoChg b
on a.ProjectID = b.ProjectID
where b.RentPrice_1Chg=1 and a.status=1;
update a
set a.Status = 0
from ODS_PROJECT_RENT_PRICE_INFO_#lastYearMonth# a
left join #InfoChgLst b
on a.ProjectID = b.ProjectID
where b.ProjectID is not null and a.status=1;
insert into ODS_PROJECT_RENT_PRICE_INFO_#lastYearMonth#
select * from #InfoChgLst;
drop table #InfoChg, #InfoChgCurr, #InfoChgLst;
--
WITH STP AS(
SELECT A.ProjectID, 2 AS PriceType, NULL AS BasePrice_1, A.RentPrice, A.MainRentPrice,
NULL SumCase1, A.VOPPAT, A.VOPPA,
CASE WHEN C.ProjectLevel = '工房1' THEN A.RentPrice*(1+24*0.012)*1.0/(1.0*(1+0.011*1.8))
WHEN C.ProjectLevel = '工房2' THEN A.RentPrice*(1+26*0.012)*1.0/(1.0*(1+0.011*1.8))
END AS GF_1Room,
CASE WHEN C.ProjectLevel = '工房1' THEN A.RentPrice*(1+16*0.012)*1.0/(1.0*(1+0.011*1.8))
WHEN C.ProjectLevel = '工房2' THEN A.RentPrice*(1+16*0.012)*1.0/(1.0*(1+0.011*1.8))
END AS GF_2Room,
CASE WHEN C.ProjectLevel = '低端公寓1' THEN A.RentPrice*1.0*(1+0.011*3.3)/(1.0*(1+0.011*1.8))
WHEN C.ProjectLevel IN ('中端公寓','低端公寓2') THEN A.RentPrice*1.0*(1+0.011*3.3)/(1.0*(1+0.011*1.8))
WHEN C.ProjectLevel IN ('高端公寓','超高端公寓') THEN A.RentPrice*(1+5*0.012)*(1+0.011*3.3)/((1.0+0.011*1.8))
END AS GY_2Room,
CASE WHEN C.ProjectLevel = '低端公寓1' THEN A.RentPrice*(1-3*0.012)*(1+0.011*4.25)/(1*(1+0.011*1.8))
WHEN C.ProjectLevel = '低端公寓2' THEN A.RentPrice*(1-4*0.012)*(1+0.011*4.25)/(1*(1+0.011*1.8))
WHEN C.ProjectLevel = '中端公寓' THEN A.RentPrice*(1-3*0.012)*(1+0.011*4.25)/(1*(1+0.011*1.8))
WHEN B.ProjectLevel IN ('高端公寓','超高端公寓') THEN A.RentPrice*(1+4*0.012)*(1+0.011*4.25)/((1+0.011*1.8))
END AS GY_3Room
FROM DWA_PROJECTBASEPRICE_RENT_MANU_#yearMonth# A
LEFT JOIN ResidenceCommunity C
ON A.ProjectID = C.CommunityId
WHERE C.CommunityId IS NULL
)
INSERT INTO ODS_PROJECT_RENT_PRICE_INFO_#yearMonth#
SELECT A.ProjectID, A.PriceType, A.BasePrice_1, A.RentPrice, A.SumCase1, A.VOPPAT, A.VOPPA, A.GF_1Room, A.GF_2Room, A.GY_2Room, A.GY_3Room,
A.GF_1Room*35 AS One_Room, A.GF_2Room*50 AS Two_Room, A.GY_3Room*105 AS Three_Three_Room, NULL EntireRentRatio, NULL EntireRentNum,
NULL ShareRentRatio, NULL ShareRentNum, NULL SaleRentRatio, GETDATE() AS ModifyDate,
1 AS Status, 'NewAdded' AdjEvd
FROM STP A
-- 更新上月价格
update a
set a.ITEM_MAINAREAPRICE = b.RentPrice
from obpm_LianCheng_Data.dbo.TLK_基价信息 a
join dbo.ODS_PROJECT_RENT_PRICE_INFO_#lastYearMonth# b
on a.ITEM_AIRAID = b.ProjectID
where b.Status = 1
and a.ITEM_VALUEPOINT = '#lastPriceDate#'
and a.ITEM_PRICETYPE = '2'
and a.ITEM_PROJECTTYPE = '1'
and a.ITEM_MAINAREAPRICE <> b.RentPrice;
-- 插入新的价格
insert into obpm_LianCheng_Data.dbo.TLK_基价信息
(
ID
, LASTMODIFIED
, FORMNAME
, AUTHOR
, AUTHOR_DEPT_INDEX
, CREATED
, FORMID
, ISTMP
, VERSIONS
, APPLICATIONID
, LASTMODIFIER
, DOMAINID
, ITEM_PriceID
, ITEM_AIRAID
, ITEM_PROJECTTYPE
, ITEM_PRICETYPE
, ITEM_MAINAREAPRICE
, ITEM_VALUEPOINT
, ITEM_PRICEEXPLAIN
, ITEM_UPDATEPERSON
, ITEM_UPDATEDATE
, ITEM_PRICECHG
)
select newid()
, getdate()
, '物业信息管理/基价信息'
, 'amQRUkvYQAsAec1JGLp'
, 'amQRUkvYQAsAec1JGLp'
, getdate()
, 'ybte0OakLV17UzAyoVU'
, 0
, 1
, 'Ts7TykYmuEzzZgWhXHj'
, 'amQRUkvYQAsAec1JGLp'
, 'BclzHtmfLQoAA5ICTb5'
, newid()
, ProjectID
, 2
, 2
, RentPrice
, '#priceDate#'
, AdjEvd
, '李贺'
, getdate()
, VOPPA
from dbo.ODS_PROJECT_RENT_PRICE_INFO_#yearMonth#
where Status = 1;
insert into obpm_LianCheng_Data.dbo.T_DOCUMENT
(
ID
, LASTMODIFIED
, FORMNAME
, AUTHOR
, AUTHOR_DEPT_INDEX
, CREATED
, FORMID
, ISTMP
, VERSIONS
, APPLICATIONID
, LASTMODIFIER
, DOMAINID
, AUDITORLIST
, COAUDITORLIST
, MAPPINGID
)
select a.ID
, a.LASTMODIFIED
, a.FORMNAME
, a.AUTHOR
, a.AUTHOR_DEPT_INDEX
, a.CREATED
, a.FORMID
, a.ISTMP
, a.VERSIONS
, a.APPLICATIONID
, a.LASTMODIFIER
, a.DOMAINID
, a.AUDITORLIST
, a.COAUDITORLIST
, a.id
from obpm_LianCheng_Data.dbo.TLK_基价信息 a
left join obpm_LianCheng_Data.dbo.T_DOCUMENT b
on a.ID = b.ID
where a.ITEM_VALUEPOINT = '#priceDate#'
and a.ITEM_PROJECTTYPE = '1'
and a.ITEM_PRICETYPE = '2';