@@ -0,0 +1,197 @@
package com.seeyon.apps.assetstenant.community ;
import com.alibaba.fastjson.JSONObject ;
import com.seeyon.apps.assetstenant.config.AssetsTenantConfigProvider ;
import com.seeyon.apps.assetstenant.constants.RentConstants ;
import com.seeyon.apps.assetstenant.file.OaFileVo ;
import com.seeyon.apps.assetstenant.po.PageQueryVo ;
import com.seeyon.cap4.form.bean.FormTableBean ;
import com.seeyon.ctp.common.AppContext ;
import com.seeyon.ctp.common.exceptions.BusinessException ;
import com.seeyon.ctp.common.filemanager.manager.AttachmentManager ;
import com.seeyon.ctp.organization.bo.V3xOrgMember ;
import com.seeyon.utils.form.* ;
import org.apache.commons.lang3.StringUtils ;
import java.math.BigDecimal ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
public class CommunityService {
private AssetsTenantConfigProvider configProvider = ( AssetsTenantConfigProvider ) AppContext . getBean ( " assetsTenantConfigProvider " ) ;
private AttachmentManager attachmentManager = ( AttachmentManager ) AppContext . getBean ( " attachmentManager " ) ;
private String getFormNo ( ) {
return configProvider . getBizConfigByKey ( RentConstants . ASSETS_FORMNO ) ;
}
public PageQueryVo pageQuery ( JSONObject params ) throws Exception {
TableContext master = FormTableExecutor . master ( getFormNo ( ) ) ;
FormTableBean masterTableBean = master . getTableBean ( ) ;
List < FormWhereCondition > conditions = buildConditions ( params , masterTableBean ) ;
Integer pageNo = params . getInteger ( " pageNo " ) = = null ? 1 : params . getInteger ( " pageNo " ) ;
Integer pageSize = params . getInteger ( " pageSize " ) = = null ? 10 : params . getInteger ( " pageSize " ) ;
PageQueryVo < CommunitityVo > pageQueryVo = new PageQueryVo ( ) ;
List < FormColumn > datas = FormTableExecutor . pageQuery ( master , null , conditions , pageNo , pageSize , true ) ;
List < CommunitityVo > vos = new ArrayList < > ( ) ;
Long count = FormTableExecutor . count ( master , null , conditions ) ;
if ( datas . size ( ) > 0 ) {
for ( Object data : datas ) {
Map < String , Object > map = ( Map < String , Object > ) data ;
CommunitityVo communitityVo = new CommunitityVo ( ) ;
fillVo ( map , communitityVo ) ;
vos . add ( communitityVo ) ;
}
pageQueryVo . setDatas ( vos ) ;
pageQueryVo . setTotalCount ( count ) ;
}
return pageQueryVo ;
}
private TableContext getTableContext ( ) throws BusinessException {
TableContext tableContext = FormTableExecutor . master ( getFormNo ( ) ) ;
return tableContext ;
}
private TableContext getSubTableContext ( ) throws BusinessException {
TableContext tableContext = FormTableExecutor . sub ( getFormNo ( ) , " 楼盘明细 " ) ;
return tableContext ;
}
// ====================== 填充楼栋VO( 严格匹配UI字段) ======================
private void fillBuildingVo ( Map < String , Object > map , CommunityBuildingVo vo ) {
vo . setSort ( getStringValue ( map , " 序号1 " ) ) ;
vo . setOpenTime ( getStringValue ( map , " 明细-开盘时间 " ) ) ;
// 注意:如果数据库没有直接的"层数/单元数/在售户数/户梯比"字段,需要从表单字段映射
// 假设表单字段如下:
// vo.setLayers(getStringValue(map, "层数"));
// vo.setUnitCount(getInteger(map, "单元数"));
// vo.setSaleHouseCount(getInteger(map, "在售户数"));
// vo.setBuildType(getStr(map, "明细-建筑类型"));
// vo.setLiftRatio(getStr(map, "户梯比"));
// vo.setAvgPrice(getBigDecimal(map, "明细-参考均价"));
}
private List < FormWhereCondition > buildConditions ( JSONObject params , FormTableBean formTableBean ) throws BusinessException {
List < FormWhereCondition > conditions = new ArrayList < > ( ) ;
if ( StringUtils . isNotBlank ( params . getString ( " communityId " ) ) ) {
conditions . add ( FormWhereCondition . build ( ) . display ( " formmain_id " ) . value ( params . getString ( " communityId " ) ) ) ;
}
if ( StringUtils . isNotBlank ( params . getString ( " assetsStatus " ) ) ) {
conditions . add ( FormWhereCondition . build ( ) . display ( " 资产状态 " ) . value ( EnumMapUtils . getEnumItemValueByDisplayValue ( formTableBean , " 资产状态 " , params . getString ( " assetsStatus " ) ) ) ) ;
}
if ( StringUtils . isNotBlank ( params . getString ( " manageType " ) ) ) {
conditions . add ( FormWhereCondition . build ( ) . display ( " 运营类型 " )
. value ( EnumMapUtils . getEnumItemValueByDisplayValue ( formTableBean , " 运营类型 " , params . getString ( " manageType " ) ) ) ) ;
}
if ( StringUtils . isNotBlank ( params . getString ( " bizZone " ) ) ) {
conditions . add ( FormWhereCondition . build ( ) . display ( " 商圈位置 " )
. value ( EnumMapUtils . getEnumItemValueByDisplayValue ( formTableBean , " 商圈位置 " , params . getString ( " bizZone " ) ) ) ) ;
}
if ( StringUtils . isNotBlank ( params . getString ( " renovationStatus " ) ) ) {
conditions . add ( FormWhereCondition . build ( ) . display ( " 装修情况 " )
. value ( EnumMapUtils . getEnumItemValueByDisplayValue ( formTableBean , " 装修情况 " , params . getString ( " renovationStatus " ) ) ) ) ;
}
if ( StringUtils . isNotBlank ( params . getString ( " layout " ) ) ) {
conditions . add ( FormWhereCondition . build ( ) . display ( " 房屋户型 " )
. value ( EnumMapUtils . getEnumItemValueByDisplayValue ( formTableBean , " 房屋户型 " , params . getString ( " layout " ) ) ) ) ;
}
if ( StringUtils . isNotBlank ( params . getString ( " rentFeeRange " ) ) ) {
String [ ] split = params . getString ( " rentFeeRange " ) . split ( " - " ) ;
String rentFeeStart = null ;
if ( split . length > 1 ) {
rentFeeStart = split [ 0 ] ;
}
String rentFeeEnd = split [ split . length - 1 ] ;
if ( rentFeeStart ! = null ) {
conditions . add ( FormWhereCondition . build ( ) . display ( " 评估-参考租金 " ) . clauseFactor ( ClauseFactor . GE )
. value ( new BigDecimal ( rentFeeStart ) ) ) ;
}
conditions . add ( FormWhereCondition . build ( ) . display ( " 评估-参考租金 " ) . clauseFactor ( ClauseFactor . LE )
. value ( new BigDecimal ( rentFeeEnd ) ) ) ;
}
if ( StringUtils . isNotBlank ( params . getString ( " features " ) ) ) {
String [ ] features = params . getString ( " features " ) . split ( " , " ) ;
for ( Object feature : features ) {
conditions . add ( FormWhereCondition . build ( ) . display ( " 基础配套 " ) . value ( EnumMapUtils . getEnumItemValueByDisplayValue ( formTableBean , " 基础配套 " , feature + " " ) )
. index ( " FIND_IN_SET(? " ) . clauseFactor ( ClauseFactor . GT ) ) ;
}
}
return conditions ;
}
public CommunitityVo queryCommunityDetail ( String communityId ) throws Exception {
TableContext tableContext = getTableContext ( ) ;
JSONObject params = new JSONObject ( ) ;
params . put ( " communityId " , communityId ) ;
List < FormWhereCondition > conditions = buildConditions ( params , tableContext . getTableBean ( ) ) ;
CommunitityVo communitityVo = new CommunitityVo ( ) ;
FormColumn formColumn = FormTableExecutor . queryOne ( tableContext , conditions , true ) ;
if ( formColumn = = null ) {
return communitityVo ;
}
Map < String , Object > fieldsMap = formColumn . getFieldsMap ( ) ;
fillVo ( fieldsMap , communitityVo ) ;
return communitityVo ;
}
public List < CommunityBuildingVo > queryBuildingList ( JSONObject params ) throws Exception {
TableContext tableContext = getSubTableContext ( ) ;
List < FormWhereCondition > conditions = buildConditions ( params , tableContext . getTableBean ( ) ) ;
List < FormColumn > formColumns = FormTableExecutor . query ( tableContext , null , conditions , true ) ;
if ( formColumns . size ( ) = = 0 ) {
return new ArrayList < > ( ) ;
}
List < CommunityBuildingVo > buildingVos = new ArrayList < > ( ) ;
Map < String , CommunityBuildingVo > buildingVoMap = new HashMap < > ( ) ;
for ( FormColumn formColumn : formColumns ) {
Map < String , Object > fieldsMap = formColumn . getFieldsMap ( ) ;
String buildingNo = getStringValue ( fieldsMap , " 明细-售卖楼栋 " ) ;
if ( ! buildingVoMap . containsKey ( buildingNo ) ) {
CommunityBuildingVo communityBuildingVo = new CommunityBuildingVo ( ) ;
communityBuildingVo . setBuildingNo ( buildingNo ) ;
communityBuildingVo . setBuildType ( getStringValue ( fieldsMap , " 明细-建筑类型 " ) ) ;
communityBuildingVo . setOpenTime ( getStringValue ( fieldsMap , " 明细-开盘时间 " ) ) ;
communityBuildingVo . setUnitNo ( buildingNo ) ;
communityBuildingVo . setSaleHouseCount ( 1 ) ;
} else {
CommunityBuildingVo buildingVo = buildingVoMap . get ( buildingNo ) ;
buildingVo . setSaleHouseCount ( buildingVo . getSaleHouseCount ( ) + 1 ) ;
}
}
buildingVos . addAll ( buildingVoMap . values ( ) ) ;
return buildingVos ;
}
public List < CommunityLayoutVo > queryLayoutList ( JSONObject params ) throws Exception {
TableContext tableContext = getSubTableContext ( ) ;
List < FormWhereCondition > conditions = buildConditions ( params , tableContext . getTableBean ( ) ) ;
List < FormColumn > formColumns = FormTableExecutor . query ( tableContext , null , conditions , true ) ;
return null ;
}
private String getStringValue ( Map < String , Object > fieldsMap , String key ) {
Object o = fieldsMap . get ( key ) ;
if ( o = = null ) {
return null ;
}
return o + " " ;
}
public void fillVo ( Map < String , Object > fieldsMap , CommunitityVo communitityVo ) throws BusinessException {
communitityVo . setCommunityId ( getStringValue ( fieldsMap , " 资产编号 " ) ) ; //楼盘id
communitityVo . setCommunityName ( getStringValue ( fieldsMap , " 品牌名称 " ) ) ; //楼盘名称
communitityVo . setFeatures ( getStringValue ( fieldsMap , " 详情信息 " ) ) ; //楼盘特点
communitityVo . setRenovation ( getStringValue ( fieldsMap , " id " ) ) ; //装修情况
communitityVo . setReferenceAvgPrice ( getStringValue ( fieldsMap , " 资产状态 " ) ) ; //楼盘参考均价
communitityVo . setReferenceTotalPrice ( getStringValue ( fieldsMap , " 资产类型 " ) ) ; //楼盘参考总价
V3xOrgMember member = null ;
BigDecimal area = ( BigDecimal ) fieldsMap . get ( " 评估-评估面积 " ) ;
BigDecimal rentFee = ( BigDecimal ) fieldsMap . get ( " 评估-参考租金 " ) ;
if ( fieldsMap . get ( " VR文件上传 " ) ! = null ) {
communitityVo . setCoverImg ( OaFileVo . getInstance ( ( Long ) fieldsMap . get ( " VR文件上传 " ) , attachmentManager ) ) ;
}
}
}