|
|
@ -1,34 +1,55 @@ |
|
|
|
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.dto.form.mq.MqBaseFormDTO; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
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.IcVolunteerPolyCategoryDao; |
|
|
|
import com.epmet.dao.IcVolunteerPolyDao; |
|
|
|
import com.epmet.dao.UserBaseInfoDao; |
|
|
|
import com.epmet.dto.IcVolunteerPolyDTO; |
|
|
|
import com.epmet.dto.VolunteerInfoDTO; |
|
|
|
import com.epmet.dto.form.VolunteerPolyListFormDTO; |
|
|
|
import com.epmet.dto.form.VolunteerPolyMapDataFormDTO; |
|
|
|
import com.epmet.dto.result.PartyUnitListbrieResultDTO; |
|
|
|
import com.epmet.dto.result.ResiUserBaseInfoResultDTO; |
|
|
|
import com.epmet.dto.result.VolunteerPolyListResultDTO; |
|
|
|
import com.epmet.dto.result.VolunteerPolyMapDataResultDTO; |
|
|
|
import com.epmet.entity.IcResiUserEntity; |
|
|
|
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 +58,19 @@ 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; |
|
|
|
@Resource |
|
|
|
private IcVolunteerPolyCategoryDao icVolunteerPolyCategoryDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<IcVolunteerPolyDTO> page(Map<String, Object> params) { |
|
|
@ -138,4 +170,265 @@ 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 |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void volunteerDataExtraction(String customerId) { |
|
|
|
if (StringUtils.isEmpty(customerId)) { |
|
|
|
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "客户ID不能为空", "客户ID不能为空"); |
|
|
|
} |
|
|
|
//获取居民信息表的志愿者
|
|
|
|
List<IcVolunteerPolyDTO> volunteerList = icResiUserDao.getVolunteerList(customerId, null); |
|
|
|
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()); |
|
|
|
item.setGender(userInfo.getGender()); |
|
|
|
} |
|
|
|
//小程序与居民信息匹配不上的志愿者拿出来
|
|
|
|
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); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 志愿者变动 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
* @Param dto |
|
|
|
* @Return |
|
|
|
* @Author zhaoqifeng |
|
|
|
* @Date 2022/5/19 16:02 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void volunteerChanged(MqBaseFormDTO dto) { |
|
|
|
if (StringUtils.isBlank(dto.getObjectId()) && CollectionUtils.isEmpty(dto.getObjectIdList())) { |
|
|
|
volunteerDataExtraction(dto.getCustomerId()); |
|
|
|
} else { |
|
|
|
if (StringUtils.isNotBlank(dto.getObjectId())) { |
|
|
|
icVolunteer(dto.getCustomerId(), dto.getObjectId()); |
|
|
|
appVolunteer(dto.getCustomerId(), dto.getObjectId()); |
|
|
|
} |
|
|
|
if (CollectionUtils.isNotEmpty(dto.getObjectIdList())) { |
|
|
|
dto.getObjectIdList().forEach(id -> { |
|
|
|
icVolunteer(dto.getCustomerId(), id); |
|
|
|
appVolunteer(dto.getCustomerId(), id); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 居民信息志愿者变动 |
|
|
|
* |
|
|
|
* @Param customerId |
|
|
|
* @Param userId |
|
|
|
* @Return |
|
|
|
* @Author zhaoqifeng |
|
|
|
* @Date 2022/5/19 16:55 |
|
|
|
*/ |
|
|
|
private void icVolunteer(String customerId, String userId) { |
|
|
|
IcResiUserEntity icUser = icResiUserDao.selectById(userId); |
|
|
|
if (null != icUser) { |
|
|
|
//设置wrapper条件
|
|
|
|
List<IcVolunteerPolyDTO> volunteerList = icResiUserDao.getVolunteerList(customerId, null); |
|
|
|
LambdaQueryWrapper<IcVolunteerPolyEntity> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
wrapper.eq(IcVolunteerPolyEntity::getCustomerId, customerId); |
|
|
|
wrapper.eq(IcVolunteerPolyEntity::getIcResiUser, userId); |
|
|
|
|
|
|
|
LambdaQueryWrapper<IcVolunteerPolyCategoryEntity> categoryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
categoryWrapper.eq(IcVolunteerPolyCategoryEntity::getCustomerId, customerId); |
|
|
|
categoryWrapper.eq(IcVolunteerPolyCategoryEntity::getIdCard, icUser.getIdCard()); |
|
|
|
|
|
|
|
//判断是否是志愿者
|
|
|
|
if (NumConstant.ONE_STR.equals(icUser.getIsVolunteer())) { |
|
|
|
if (CollectionUtils.isNotEmpty(volunteerList)) { |
|
|
|
|
|
|
|
IcVolunteerPolyEntity volunteer = baseDao.selectOne(wrapper); |
|
|
|
IcVolunteerPolyEntity entity = ConvertUtils.sourceToTarget(volunteerList.get(NumConstant.ZERO), IcVolunteerPolyEntity.class); |
|
|
|
if (null != volunteer) { |
|
|
|
entity.setId(volunteer.getId()); |
|
|
|
baseDao.updateById(entity); |
|
|
|
} else { |
|
|
|
baseDao.insert(entity); |
|
|
|
} |
|
|
|
List<String> categoryList = Arrays.asList(volunteerList.get(NumConstant.ZERO).getVolunteerCategory().split(StrConstant.COMMA)); |
|
|
|
List<IcVolunteerPolyCategoryEntity> entityList = categoryList.stream().map(o -> { |
|
|
|
IcVolunteerPolyCategoryEntity category = new IcVolunteerPolyCategoryEntity(); |
|
|
|
category.setCustomerId(entity.getCustomerId()); |
|
|
|
category.setIdCard(entity.getIdCard()); |
|
|
|
if (null != volunteer) { |
|
|
|
category.setLatitude(volunteer.getLatitude()); |
|
|
|
category.setLongitude(volunteer.getLongitude()); |
|
|
|
} |
|
|
|
category.setVolunteerCategory(o); |
|
|
|
return category; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
icVolunteerPolyCategoryDao.delete(categoryWrapper); |
|
|
|
icVolunteerPolyCategoryService.insertBatch(entityList); |
|
|
|
} |
|
|
|
} else { |
|
|
|
//删除志愿者信息
|
|
|
|
baseDao.delete(wrapper); |
|
|
|
icVolunteerPolyCategoryDao.delete(categoryWrapper); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 居民端小程序志愿者变动 |
|
|
|
* |
|
|
|
* @Param customerId |
|
|
|
* @Param userId |
|
|
|
* @Return |
|
|
|
* @Author zhaoqifeng |
|
|
|
* @Date 2022/5/19 16:55 |
|
|
|
*/ |
|
|
|
private void appVolunteer(String customerId, String userId) { |
|
|
|
ResiUserBaseInfoResultDTO user = userBaseInfoDao.selecUserBaseInfoByUserId(userId); |
|
|
|
if (null != user) { |
|
|
|
//获取志愿者信息
|
|
|
|
Result<VolunteerInfoDTO> volunteerResult = epmetHeartOpenFeignClient.queryUserVolunteerInfo(userId); |
|
|
|
if (!volunteerResult.success()) { |
|
|
|
log.error("志愿者变更-获取小程序志愿者失败"); |
|
|
|
} |
|
|
|
|
|
|
|
//判断是否是志愿者
|
|
|
|
if (null != volunteerResult.getData()) { |
|
|
|
VolunteerInfoDTO appVolunteer = volunteerResult.getData(); |
|
|
|
//设置wrapper条件
|
|
|
|
LambdaQueryWrapper<IcVolunteerPolyEntity> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
wrapper.eq(IcVolunteerPolyEntity::getCustomerId, customerId); |
|
|
|
wrapper.eq(IcVolunteerPolyEntity::getUserId, userId); |
|
|
|
|
|
|
|
LambdaQueryWrapper<IcVolunteerPolyCategoryEntity> categoryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
categoryWrapper.eq(IcVolunteerPolyCategoryEntity::getCustomerId, customerId); |
|
|
|
categoryWrapper.eq(IcVolunteerPolyCategoryEntity::getIdCard, user.getIdNum()); |
|
|
|
|
|
|
|
IcVolunteerPolyEntity volunteer = baseDao.selectOne(wrapper); |
|
|
|
|
|
|
|
IcVolunteerPolyEntity entity = new IcVolunteerPolyEntity(); |
|
|
|
entity.setUserId(userId); |
|
|
|
entity.setCustomerId(customerId); |
|
|
|
entity.setAgencyId(appVolunteer.getPid()); |
|
|
|
entity.setAgencyPids(appVolunteer.getPids()); |
|
|
|
entity.setGender(user.getGender()); |
|
|
|
entity.setName(user.getRealName()); |
|
|
|
entity.setIdCard(user.getIdNum()); |
|
|
|
|
|
|
|
//根据身份证判断有没有匹配的居民信息
|
|
|
|
LambdaQueryWrapper<IcResiUserEntity> icUserWrapper = new LambdaQueryWrapper<>(); |
|
|
|
icUserWrapper.eq(IcResiUserEntity::getCustomerId, customerId); |
|
|
|
icUserWrapper.eq(IcResiUserEntity::getIdCard, user.getIdNum()); |
|
|
|
IcResiUserEntity icResiUser = icResiUserDao.selectOne(icUserWrapper); |
|
|
|
|
|
|
|
|
|
|
|
if (null != volunteer && StringUtils.isBlank(volunteer.getIcResiUser())) { |
|
|
|
entity.setId(volunteer.getId()); |
|
|
|
if (null != icResiUser) { |
|
|
|
entity.setIcResiUser(icResiUser.getId()); |
|
|
|
} |
|
|
|
baseDao.updateById(entity); |
|
|
|
|
|
|
|
IcVolunteerPolyCategoryEntity category = new IcVolunteerPolyCategoryEntity(); |
|
|
|
category.setCustomerId(entity.getCustomerId()); |
|
|
|
category.setIdCard(entity.getIdCard()); |
|
|
|
category.setLatitude(volunteer.getLatitude()); |
|
|
|
category.setLongitude(volunteer.getLongitude()); |
|
|
|
category.setVolunteerCategory("qita"); |
|
|
|
|
|
|
|
icVolunteerPolyCategoryDao.delete(categoryWrapper); |
|
|
|
icVolunteerPolyCategoryDao.insert(category); |
|
|
|
} else if (null == volunteer) { |
|
|
|
if (null != icResiUser) { |
|
|
|
entity.setIcResiUser(icResiUser.getId()); |
|
|
|
} |
|
|
|
baseDao.insert(entity); |
|
|
|
IcVolunteerPolyCategoryEntity category = new IcVolunteerPolyCategoryEntity(); |
|
|
|
category.setCustomerId(entity.getCustomerId()); |
|
|
|
category.setIdCard(entity.getIdCard()); |
|
|
|
category.setLatitude(volunteer.getLatitude()); |
|
|
|
category.setLongitude(volunteer.getLongitude()); |
|
|
|
category.setVolunteerCategory("qita"); |
|
|
|
|
|
|
|
icVolunteerPolyCategoryDao.delete(categoryWrapper); |
|
|
|
icVolunteerPolyCategoryDao.insert(category); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<UserBaseInfoEntity> getUserInfoList(List<String> userIds) { |
|
|
|
LambdaQueryWrapper<UserBaseInfoEntity> userInfoWrapper = new LambdaQueryWrapper<>(); |
|
|
|
userInfoWrapper.in(UserBaseInfoEntity::getUserId, userIds); |
|
|
|
return userBaseInfoDao.selectList(userInfoWrapper); |
|
|
|
} |
|
|
|
|
|
|
|
} |