|
|
@ -1,34 +1,48 @@ |
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerIcHouseRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.HouseInfoCache; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dao.IcResiUserDao; |
|
|
|
import com.epmet.dao.IcVolunteerPolyDao; |
|
|
|
import com.epmet.dao.UserBaseInfoDao; |
|
|
|
import com.epmet.dto.IcVolunteerPolyDTO; |
|
|
|
import com.epmet.dto.form.VolunteerPolyListFormDTO; |
|
|
|
import com.epmet.dto.form.VolunteerPolyMapDataFormDTO; |
|
|
|
import com.epmet.dto.result.PartyUnitListbrieResultDTO; |
|
|
|
import com.epmet.dto.result.VolunteerPolyListResultDTO; |
|
|
|
import com.epmet.dto.result.VolunteerPolyMapDataResultDTO; |
|
|
|
import com.epmet.entity.IcVolunteerPolyCategoryEntity; |
|
|
|
import com.epmet.entity.IcVolunteerPolyEntity; |
|
|
|
import com.epmet.entity.UserBaseInfoEntity; |
|
|
|
import com.epmet.feign.EpmetHeartOpenFeignClient; |
|
|
|
import com.epmet.service.IcVolunteerPolyCategoryService; |
|
|
|
import com.epmet.service.IcVolunteerPolyService; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.collections4.ListUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 志愿者信息聚合 |
|
|
@ -37,8 +51,18 @@ import java.util.Map; |
|
|
|
* @since v1.0.0 2022-05-19 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class IcVolunteerPolyServiceImpl extends BaseServiceImpl<IcVolunteerPolyDao, IcVolunteerPolyEntity> implements IcVolunteerPolyService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private IcResiUserDao icResiUserDao; |
|
|
|
@Resource |
|
|
|
private EpmetHeartOpenFeignClient epmetHeartOpenFeignClient; |
|
|
|
@Resource |
|
|
|
private UserBaseInfoDao userBaseInfoDao; |
|
|
|
@Resource |
|
|
|
private IcVolunteerPolyCategoryService icVolunteerPolyCategoryService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<IcVolunteerPolyDTO> page(Map<String, Object> params) { |
|
|
@ -138,4 +162,90 @@ public class IcVolunteerPolyServiceImpl extends BaseServiceImpl<IcVolunteerPolyD |
|
|
|
return new PageData<>(result, info.getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 志愿者数据抽取 |
|
|
|
* |
|
|
|
* @param customerId |
|
|
|
* @Param customerId |
|
|
|
* @Return void |
|
|
|
* @Author zhaoqifeng |
|
|
|
* @Date 2022/5/19 10:00 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void volunteerDataExtraction(String customerId) { |
|
|
|
//获取居民信息表的志愿者
|
|
|
|
List<IcVolunteerPolyDTO> volunteerList = icResiUserDao.getVolunteerList(customerId); |
|
|
|
if (CollectionUtils.isEmpty(volunteerList)) { |
|
|
|
volunteerList = new ArrayList<>(); |
|
|
|
} |
|
|
|
//获取小程序居民端志愿者
|
|
|
|
Result<List<IcVolunteerPolyDTO>> result = epmetHeartOpenFeignClient.getVolunteerList(customerId); |
|
|
|
if (!result.success()) { |
|
|
|
log.error("志愿者数据抽取-获取小程序志愿者失败"); |
|
|
|
} |
|
|
|
List<IcVolunteerPolyDTO> appVolunteerList = result.getData(); |
|
|
|
if (CollectionUtils.isNotEmpty(appVolunteerList)) { |
|
|
|
//获取居民信息
|
|
|
|
List<String> userIds = appVolunteerList.stream().map(IcVolunteerPolyDTO::getUserId).collect(Collectors.toList()); |
|
|
|
|
|
|
|
//根据志愿者的userId获取居民信息并转成map
|
|
|
|
List<UserBaseInfoEntity> userList = new ArrayList<>(); |
|
|
|
List<List<String>> partition = ListUtils.partition(userIds, NumConstant.FIFTY); |
|
|
|
partition.forEach(part -> userList.addAll(getUserInfoList(part))); |
|
|
|
Map<String, UserBaseInfoEntity> userMap = userList.stream().collect(Collectors.toMap(UserBaseInfoEntity::getUserId, a -> a, (o, n) -> o)); |
|
|
|
//将居民志愿者转成map
|
|
|
|
Map<String, IcVolunteerPolyDTO> volunteerMap = volunteerList.stream().collect(Collectors.toMap(IcVolunteerPolyDTO::getIdCard,a -> a, (o, n) -> o)); |
|
|
|
//小程序与居民信息匹配不上的志愿者
|
|
|
|
List<IcVolunteerPolyDTO> notInList = new ArrayList<>(); |
|
|
|
appVolunteerList.forEach(item -> { |
|
|
|
//补充志愿者信息
|
|
|
|
if (userMap.containsKey(item.getUserId())) { |
|
|
|
UserBaseInfoEntity userInfo = userMap.get(item.getUserId()); |
|
|
|
item.setName(userInfo.getRealName()); |
|
|
|
item.setIdCard(userInfo.getIdNum()); |
|
|
|
item.setMobile(userInfo.getMobile()); |
|
|
|
} |
|
|
|
//小程序与居民信息匹配不上的志愿者拿出来
|
|
|
|
if (!volunteerMap.containsKey(item.getIdCard())) { |
|
|
|
notInList.add(item); |
|
|
|
} |
|
|
|
}); |
|
|
|
//将小程序的志愿者列表转成map
|
|
|
|
Map<String, IcVolunteerPolyDTO> appVolunteerMap = appVolunteerList.stream().collect(Collectors.toMap(IcVolunteerPolyDTO::getIdCard,a -> a, (o, n) -> o)); |
|
|
|
////小程序与居民信息匹配上的志愿者userId更新到居民志愿者列表
|
|
|
|
volunteerList.forEach(item -> { |
|
|
|
if (appVolunteerMap.containsKey(item.getIdCard())) { |
|
|
|
item.setUserId(appVolunteerMap.get(item.getIdCard()).getUserId()); |
|
|
|
} |
|
|
|
}); |
|
|
|
volunteerList.addAll(notInList); |
|
|
|
} |
|
|
|
if (CollectionUtils.isNotEmpty(volunteerList)) { |
|
|
|
//删除原数据
|
|
|
|
baseDao.deleteDataByCustomerId(customerId); |
|
|
|
baseDao.deleteCategoryByCustomerId(customerId); |
|
|
|
//保存新数据
|
|
|
|
volunteerList.forEach(item -> { |
|
|
|
IcVolunteerPolyEntity entity = ConvertUtils.sourceToTarget(item, IcVolunteerPolyEntity.class); |
|
|
|
baseDao.insert(entity); |
|
|
|
List<String> categoryList = Arrays.asList(item.getVolunteerCategory().split(StrConstant.COMMA)); |
|
|
|
List<IcVolunteerPolyCategoryEntity> entityList = categoryList.stream().map(o -> { |
|
|
|
IcVolunteerPolyCategoryEntity category = new IcVolunteerPolyCategoryEntity(); |
|
|
|
category.setCustomerId(item.getCustomerId()); |
|
|
|
category.setIdCard(item.getIdCard()); |
|
|
|
category.setLatitude(item.getLatitude()); |
|
|
|
category.setLongitude(item.getLongitude()); |
|
|
|
category.setVolunteerCategory(o); |
|
|
|
return category; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
icVolunteerPolyCategoryService.insertBatch(entityList); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
private List<UserBaseInfoEntity> getUserInfoList(List<String> userIds) { |
|
|
|
LambdaQueryWrapper<UserBaseInfoEntity> userInfoWrapper = new LambdaQueryWrapper<>(); |
|
|
|
userInfoWrapper.in(UserBaseInfoEntity::getUserId, userIds); |
|
|
|
return userBaseInfoDao.selectList(userInfoWrapper); |
|
|
|
} |
|
|
|
|
|
|
|
} |