@ -2,12 +2,10 @@ package com.epmet.service.impl;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams ;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult ;
import com.epmet.commons.tools.enums.OrgTypeEnum ;
import com.epmet.commons.tools.enums.OrgTypeEnum ;
import com.epmet.commons.tools.exception.EpmetErrorCode ;
import com.epmet.commons.tools.exception.EpmetErrorCode ;
import com.epmet.commons.tools.exception.RenException ;
import com.epmet.commons.tools.exception.RenException ;
import com.epmet.commons.tools.page.PageData ;
import com.epmet.commons.tools.page.PageData ;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis ;
import com.epmet.commons.tools.utils.ConvertUtils ;
import com.epmet.commons.tools.utils.ConvertUtils ;
import com.epmet.commons.tools.utils.Result ;
import com.epmet.commons.tools.utils.Result ;
import com.epmet.constant.NeighborhoodConstant ;
import com.epmet.constant.NeighborhoodConstant ;
@ -19,7 +17,9 @@ import com.epmet.dto.form.IcHouseListFormDTO;
import com.epmet.dto.form.IcNeighborHoodAddFormDTO ;
import com.epmet.dto.form.IcNeighborHoodAddFormDTO ;
import com.epmet.dto.form.IcNeighborHoodListFormDTO ;
import com.epmet.dto.form.IcNeighborHoodListFormDTO ;
import com.epmet.dto.result.IcNeighborHoodResultDTO ;
import com.epmet.dto.result.IcNeighborHoodResultDTO ;
import com.epmet.entity.* ;
import com.epmet.entity.IcHouseEntity ;
import com.epmet.entity.IcNeighborHoodEntity ;
import com.epmet.entity.IcNeighborHoodPropertyEntity ;
import com.epmet.excel.IcNeighborHoodExcel ;
import com.epmet.excel.IcNeighborHoodExcel ;
import com.epmet.feign.GovOrgOpenFeignClient ;
import com.epmet.feign.GovOrgOpenFeignClient ;
import com.epmet.service.IcNeighborHoodPropertyService ;
import com.epmet.service.IcNeighborHoodPropertyService ;
@ -32,15 +32,14 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.util.CollectionUtils ;
import org.springframework.util.StringUtils ;
import org.springframework.util.StringUtils ;
import javax.annotation.Resource ;
import javax.annotation.Resource ;
import javax.servlet.http.HttpServletResponse ;
import javax.servlet.http.HttpServletResponse ;
import java.util.* ;
import java.util.HashMap ;
import java.util.concurrent.atomic.AtomicBoolean ;
import java.util.List ;
import java.util.function.Function ;
import java.util.Map ;
import java.util.stream.Collectors ;
import java.util.Optional ;
@Slf4j
@Slf4j
@Service
@Service
@ -48,29 +47,15 @@ public class NeighborHoodServiceImpl implements NeighborHoodService {
@Autowired
@Autowired
private GovOrgOpenFeignClient govOrgOpenFeignClient ;
private GovOrgOpenFeignClient govOrgOpenFeignClient ;
@Autowired
@Autowired
private IcNeighborHoodService icNeighborHoodService ;
private IcNeighborHoodService icNeighborHoodService ;
@Autowired
@Autowired
private IcNeighborHoodPropertyService icNeighborHoodPropertyService ;
private IcNeighborHoodPropertyService icNeighborHoodPropertyService ;
@Resource
@Resource
private IcNeighborHoodPropertyDao icNeighborHoodPropertyDao ;
private IcNeighborHoodPropertyDao icNeighborHoodPropertyDao ;
@Resource
@Resource
private IcNeighborHoodDao icNeighborHoodDao ;
private IcNeighborHoodDao icNeighborHoodDao ;
@Resource
private IcBuildingDao icBuildingDao ;
@Resource
private IcHouseDao icHouseDao ;
@Resource
private CustomerAgencyDao customerAgencyDao ;
@Resource
private CustomerGridDao customerGridDao ;
@Resource
private IcPropertyManagementDao icPropertyManagementDao ;
@Override
@Override
@Transactional ( rollbackFor = Exception . class )
@Transactional ( rollbackFor = Exception . class )
@ -168,8 +153,6 @@ public class NeighborHoodServiceImpl implements NeighborHoodService {
//更新
//更新
icNeighborHoodPropertyService . updateById ( icNeighborHoodProperty ) ;
icNeighborHoodPropertyService . updateById ( icNeighborHoodProperty ) ;
}
}
}
}
}
}
@ -199,7 +182,6 @@ public class NeighborHoodServiceImpl implements NeighborHoodService {
public void exportNeighborhoodinfo ( IcHouseListFormDTO formDTO , HttpServletResponse response ) throws Exception {
public void exportNeighborhoodinfo ( IcHouseListFormDTO formDTO , HttpServletResponse response ) throws Exception {
//导出小区
//导出小区
List < IcNeighborHoodExcel > icNeighborHoodExcels = searchAllNeighborhood ( formDTO ) ;
List < IcNeighborHoodExcel > icNeighborHoodExcels = searchAllNeighborhood ( formDTO ) ;
// ExcelUtils.exportExcelToTarget(response, "小区信息录入表", icNeighborHoodExcels, IcNeighborHoodExcel.class);
TemplateExportParams templatePath = new TemplateExportParams ( "excel/neighbor_export.xlsx" ) ;
TemplateExportParams templatePath = new TemplateExportParams ( "excel/neighbor_export.xlsx" ) ;
Map < String , Object > map = new HashMap < > ( ) ;
Map < String , Object > map = new HashMap < > ( ) ;
@ -207,119 +189,7 @@ public class NeighborHoodServiceImpl implements NeighborHoodService {
ExcelPoiUtils . exportExcel ( templatePath , map , "小区信息录入表" , response ) ;
ExcelPoiUtils . exportExcel ( templatePath , map , "小区信息录入表" , response ) ;
}
}
@Override
@Transactional ( rollbackFor = Exception . class )
public List < Integer > importExcel ( String customerId , List < IcNeighborHoodExcel > list , String staffId , List < Integer > numList ) {
//2021.11.9 需求变更 当前工作人员只能导致自己所属组织下数据,网格名对应不上的数据舍弃【注:需求就这样】 sun
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis . getStaffInfo ( customerId , staffId ) ;
//查询当前组织下网格列表
List < CustomerGridEntity > customerGridList = customerGridDao . selectByPid ( staffInfoCache . getAgencyId ( ) ) ;
//组织名称不一样的数据舍弃
Iterator < IcNeighborHoodExcel > iterator = list . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
IcNeighborHoodExcel obj = iterator . next ( ) ;
if ( ! obj . getAgencyName ( ) . trim ( ) . equals ( staffInfoCache . getAgencyName ( ) ) ) {
numList . add ( obj . getRowNum ( ) ) ;
iterator . remove ( ) ;
continue ;
}
//当前组织下网格名不存在的也不允许导入
AtomicBoolean br = new AtomicBoolean ( true ) ;
customerGridList . forEach ( g - > {
if ( obj . getGridName ( ) . trim ( ) . equals ( g . getGridName ( ) ) ) {
br . set ( false ) ;
}
} ) ;
if ( br . get ( ) ) {
numList . add ( obj . getRowNum ( ) ) ;
iterator . remove ( ) ;
}
}
//end sun
//导入
if ( CollectionUtils . isEmpty ( list ) ) {
return numList ;
}
//获取所有组织 list
List < String > agencyNameList = list . stream ( ) . map ( item - > item . getAgencyName ( ) ) . collect ( Collectors . toList ( ) ) ;
agencyNameList = agencyNameList . stream ( ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
//获取所有网格 list
//List<String> gridNameList = list.stream().map(item->item.getGridName()).collect(Collectors.toList());
//获取所有物业 list
List < String > propertyNameList = list . stream ( ) . map ( item - > item . getPropertyName ( ) ) . collect ( Collectors . toList ( ) ) ;
propertyNameList = propertyNameList . stream ( ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
//查询对应的id
List < CustomerAgencyEntity > customerAgencyList = customerAgencyDao . selectList ( new QueryWrapper < CustomerAgencyEntity > ( ) . lambda ( ) . in ( CustomerAgencyEntity : : getOrganizationName , agencyNameList ) ) ;
//List<CustomerGridEntity> customerGridList = customerGridDao.selectList(new QueryWrapper<CustomerGridEntity>().lambda().in(CustomerGridEntity::getGridName, gridNameList));
List < IcPropertyManagementEntity > icPropertyManagementList = icPropertyManagementDao . selectList ( new QueryWrapper < IcPropertyManagementEntity > ( ) . lambda ( ) . in ( IcPropertyManagementEntity : : getName , propertyNameList ) ) ;
Map < String , CustomerAgencyEntity > agencyMap = customerAgencyList . stream ( ) . collect ( Collectors . toMap ( CustomerAgencyEntity : : getOrganizationName , Function . identity ( ) , ( key1 , key2 ) - > key1 ) ) ;
Map < String , CustomerGridEntity > gridMap = customerGridList . stream ( ) . collect ( Collectors . toMap ( CustomerGridEntity : : getGridName , Function . identity ( ) , ( key1 , key2 ) - > key1 ) ) ;
Map < String , IcPropertyManagementEntity > propertyMap = icPropertyManagementList . stream ( ) . collect ( Collectors . toMap ( IcPropertyManagementEntity : : getName , Function . identity ( ) , ( key1 , key2 ) - > key1 ) ) ;
//封装数据
List < IcNeighborHoodEntity > neighborHoodEntityList = new ArrayList < > ( ) ;
List < IcNeighborHoodPropertyEntity > icNeighborHoodPropertyEntityList = new ArrayList < > ( ) ;
Iterator < IcNeighborHoodExcel > iterator1 = list . iterator ( ) ;
while ( iterator1 . hasNext ( ) ) {
IcNeighborHoodExcel icNeighborHoodExcel = iterator1 . next ( ) ;
//同一客户下,小区名称唯一
Integer count = icNeighborHoodDao . checkNameUq ( customerId , icNeighborHoodExcel . getNeighborHoodName ( ) , null ) ;
if ( null ! = count & & count > 0 ) {
//throw new RenException(EpmetErrorCode.NEIGHBOOR_NAME_EXITED.getCode(), icNeighborHoodExcel.getNeighborHoodName()+EpmetErrorCode.NEIGHBOOR_NAME_EXITED.getMsg());
log . error ( icNeighborHoodExcel . getNeighborHoodName ( ) + EpmetErrorCode . NEIGHBOOR_NAME_EXITED . getMsg ( ) ) ;
numList . add ( icNeighborHoodExcel . getRowNum ( ) ) ;
iterator1 . remove ( ) ;
continue ;
}
IcNeighborHoodEntity entity = new IcNeighborHoodEntity ( ) ;
String uuid = UUID . randomUUID ( ) . toString ( ) . replace ( "-" , "" ) ;
entity . setId ( uuid ) ;
entity . setCustomerId ( customerId ) ;
entity . setNeighborHoodName ( icNeighborHoodExcel . getNeighborHoodName ( ) ) ;
entity . setAgencyId ( Optional . ofNullable ( agencyMap . get ( icNeighborHoodExcel . getAgencyName ( ) . trim ( ) ) ) . map ( u - > u . getId ( ) ) . orElse ( "" ) ) ; // agencyMap.get(icNeighborHoodExcel.getAgencyName()).getId());
entity . setParentAgencyId ( Optional . ofNullable ( agencyMap . get ( icNeighborHoodExcel . getAgencyName ( ) . trim ( ) ) ) . map ( u - > u . getPid ( ) ) . orElse ( "" ) ) ; //agencyMap.get(icNeighborHoodExcel.getAgencyName()).getPid()
entity . setAgencyPids ( Optional . ofNullable ( agencyMap . get ( icNeighborHoodExcel . getAgencyName ( ) . trim ( ) ) ) . map ( u - > u . getPids ( ) ) . orElse ( "" ) ) ; //agencyMap.get(icNeighborHoodExcel.getAgencyName()).getPids()
entity . setGridId ( Optional . ofNullable ( gridMap . get ( icNeighborHoodExcel . getGridName ( ) . trim ( ) ) ) . map ( u - > u . getId ( ) ) . orElse ( "" ) ) ; //gridMap.get(icNeighborHoodExcel.getGridName()).getId()
//网格名对应不上的数据舍弃
if ( "" . equals ( entity . getGridId ( ) ) ) {
numList . add ( icNeighborHoodExcel . getRowNum ( ) ) ;
iterator1 . remove ( ) ;
continue ;
}
entity . setAddress ( icNeighborHoodExcel . getAddress ( ) ) ;
entity . setRemark ( icNeighborHoodExcel . getRemark ( ) ) ;
neighborHoodEntityList . add ( entity ) ;
IcNeighborHoodPropertyEntity entity1 = new IcNeighborHoodPropertyEntity ( ) ;
entity1 . setPropertyId ( Optional . ofNullable ( propertyMap . get ( icNeighborHoodExcel . getPropertyName ( ) ) ) . map ( u - > u . getId ( ) ) . orElse ( "" ) ) ;
entity1 . setNeighborHoodId ( uuid ) ;
icNeighborHoodPropertyEntityList . add ( entity1 ) ;
}
// icNeighborHoodDao.
//保存
icNeighborHoodService . insertBatch ( neighborHoodEntityList ) ;
icNeighborHoodPropertyService . insertBatch ( icNeighborHoodPropertyEntityList ) ;
return numList ;
}
private List < IcNeighborHoodExcel > searchAllNeighborhood ( IcHouseListFormDTO formDTO ) {
private List < IcNeighborHoodExcel > searchAllNeighborhood ( IcHouseListFormDTO formDTO ) {
// QueryWrapper<IcNeighborHoodEntity> neighborHoodEntityQueryWrapper = new QueryWrapper<>();
// neighborHoodEntityQueryWrapper.lambda()
// .eq(!StringUtils.isEmpty(formDTO.getAgencyId()),IcNeighborHoodEntity::getAgencyId,formDTO.getAgencyId())
// .eq(!StringUtils.isEmpty(formDTO.getGridId()),IcNeighborHoodEntity::getId,formDTO.getGridId())
// .eq(!StringUtils.isEmpty(formDTO.getNeighborHoodId()),IcNeighborHoodEntity::getId,formDTO.getNeighborHoodId())
// .like(!StringUtils.isEmpty(formDTO.getNeighborHoodName()),IcNeighborHoodEntity::getNeighborHoodName,formDTO.getNeighborHoodName());
// neighborHoodEntityQueryWrapper.eq("a.DEL_FLAG","0");
IcNeighborHoodEntity neighbor = ConvertUtils . sourceToTarget ( formDTO , IcNeighborHoodEntity . class ) ;
IcNeighborHoodEntity neighbor = ConvertUtils . sourceToTarget ( formDTO , IcNeighborHoodEntity . class ) ;
neighbor . setDelFlag ( "0" ) ;
neighbor . setDelFlag ( "0" ) ;
if ( OrgTypeEnum . GRID . getCode ( ) . equals ( formDTO . getLevel ( ) ) ) {
if ( OrgTypeEnum . GRID . getCode ( ) . equals ( formDTO . getLevel ( ) ) ) {
@ -330,10 +200,4 @@ public class NeighborHoodServiceImpl implements NeighborHoodService {
IcHouseEntity house = ConvertUtils . sourceToTarget ( formDTO , IcHouseEntity . class ) ;
IcHouseEntity house = ConvertUtils . sourceToTarget ( formDTO , IcHouseEntity . class ) ;
return icNeighborHoodDao . searchAllNeighborhood ( neighbor , house ) ;
return icNeighborHoodDao . searchAllNeighborhood ( neighbor , house ) ;
}
}
}
}