package com.zzg.system.service.state.impl;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
import com.alibaba.excel.EasyExcelFactory;
|
import com.alibaba.fastjson2.JSON;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.github.pagehelper.PageInfo;
|
import com.zzg.common.core.domain.BaseEntity;
|
import com.zzg.common.core.domain.entity.state.*;
|
import com.zzg.common.enums.*;
|
import com.zzg.common.exception.GlobalException;
|
import com.zzg.common.utils.DateUtils;
|
import com.zzg.common.utils.FileUtil;
|
import com.zzg.common.utils.PageUtils;
|
import com.zzg.common.utils.SecurityUtils;
|
import com.zzg.system.convert.StateProjectConvert;
|
import com.zzg.system.domain.bo.*;
|
import com.zzg.system.domain.vo.ApplyHouseholdOwnerVO;
|
import com.zzg.system.domain.vo.ApplyOwnerVO;
|
import com.zzg.system.domain.vo.StateApplyRecordPageInfoLevelVO;
|
import com.zzg.system.domain.vo.StateApplyRecordVO;
|
import com.zzg.system.mapper.state.StateApplyRecordMapper;
|
import com.zzg.system.service.state.*;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
|
import javax.annotation.Resource;
|
import java.io.IOException;
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.text.DecimalFormat;
|
import java.time.LocalDate;
|
import java.util.*;
|
import java.util.function.Function;
|
import java.util.stream.Collectors;
|
|
@Service
|
@RequiredArgsConstructor
|
public class StateApplyRecordServiceImpl extends ServiceImpl<StateApplyRecordMapper, StateApplyRecord> implements StateApplyRecordService {
|
private final StateProjectService stateProjectService;
|
private final StateApplyRecordItemService stateApplyRecordItemService;
|
private final StateHouseholdService stateHouseholdService;
|
private final StateHouseholdOwnerService stateHouseholdOwnerService;
|
private final StateProjectCompensationService stateProjectCompensationService;
|
private final StateProjectCompensateStandardService stateProjectCompensateStandardService;
|
private final StateProcessTemplateService stateProcessTemplateService;
|
|
@Lazy
|
@Resource
|
private StateApplyRecordService stateApplyRecordService;
|
|
/**
|
* 分页查询
|
* @param stateApplyRecordPageBO
|
* @return
|
*/
|
@Override
|
public PageInfo<StateApplyRecordVO> pageInfo(StateApplyRecordPageBO stateApplyRecordPageBO) {
|
PageUtils.startPage();
|
adjustEndTime(stateApplyRecordPageBO);
|
List<StateApplyRecordVO> stateApplyRecordVOS = this.getBaseMapper().selectProjectWithApplyRecord(stateApplyRecordPageBO);
|
PageInfo<StateApplyRecordVO> stateApplyRecordVOPageInfo = new PageInfo<>(stateApplyRecordVOS);
|
if (CollectionUtils.isEmpty(stateApplyRecordVOPageInfo.getList())) {
|
return new PageInfo<>();
|
}
|
for (StateApplyRecordVO e : stateApplyRecordVOPageInfo.getList()) {
|
e.setApplyStatusStr(SubmitStatusEnum.getTextByValue(e.getApplyStatus()));
|
e.setApplyTypeStr(ApplyTypeEnum.getTextByValue(e.getApplyType()));
|
e.setDistributionAmount(e.getAmount());
|
}
|
stateApplyRecordVOPageInfo.getList().sort(Comparator.comparing(BaseEntity::getCreateTime).reversed());
|
return stateApplyRecordVOPageInfo;
|
}
|
|
public void adjustEndTime(StateApplyRecordPageBO stateApplyRecordPageBO) {
|
// 获取 applyStartTime 和 applyEndTime
|
LocalDate applyStartTime = stateApplyRecordPageBO.getApplyStartTime();
|
LocalDate applyEndTime = stateApplyRecordPageBO.getApplyEndTime();
|
|
// 如果开始时间和结束时间相同,则延长结束时间一天
|
if (applyStartTime != null && applyStartTime.equals(applyEndTime)) {
|
applyEndTime = applyEndTime.plusDays(1);
|
stateApplyRecordPageBO.setApplyEndTime(applyEndTime); // 设置新的结束时间
|
}
|
}
|
|
/**
|
* 保存请账
|
* @param recordAndItemBO
|
* @return
|
*/
|
@Override
|
@Transactional
|
public boolean saveStateApplyRecordAndItem(SaveRecordAndItemBO recordAndItemBO) {
|
StateApplyRecord stateApplyRecord = StateProjectConvert.INSTANCE.toStateApplyRecord(recordAndItemBO);
|
List<StateApplyRecordItem> recordItem = StateProjectConvert.INSTANCE.toStateApplyRecordItem(recordAndItemBO.getApplyOwnerBOList());
|
StateApplyRecordItem item;
|
List<StateApplyRecordItem> newRecordItem = new ArrayList<>();
|
for (StateApplyRecordItem stateApplyRecordItem : recordItem) {
|
if (stateApplyRecordItem.getOwnerName().contains("|") && stateApplyRecordItem.getStateHouseholdOwnerId().contains("|")) {
|
|
String[] splitOwnerName = stateApplyRecordItem.getOwnerName().split("\\|");
|
String[] splitOwnerId = stateApplyRecordItem.getStateHouseholdOwnerId().split("\\|");
|
for (int i = 0; i < splitOwnerName.length; i++) {
|
item = StateProjectConvert.INSTANCE.copyStateApplyRecordItem(stateApplyRecordItem);
|
item.setOwnerName(splitOwnerName[i]);
|
item.setStateHouseholdOwner(splitOwnerId[i]);
|
item.setStateHouseholdOwnerId(splitOwnerId[i]);
|
newRecordItem.add(item);
|
}
|
} else {
|
newRecordItem.add(stateApplyRecordItem);
|
}
|
}
|
stateApplyRecord.setFileUrl(JSON.toJSONString(recordAndItemBO.getFileBOList()));
|
//审核中
|
stateApplyRecord.setApplyStatus(SubmitStatusEnum.PENDING_REVIEW.getValue());
|
if (SecurityUtils.getLoginUser() != null && SecurityUtils.getLoginUser().getUser() != null) {
|
if (SecurityUtils.getLoginUser().getUser().getNickName() != null) {
|
stateApplyRecord.setApplyUser(SecurityUtils.getLoginUser().getUser().getNickName());
|
}
|
|
if (SecurityUtils.getLoginUser().getUser().getDept() != null &&
|
SecurityUtils.getLoginUser().getUser().getDept().getDeptName() != null) {
|
stateApplyRecord.setApplyDepartment(SecurityUtils.getLoginUser().getUser().getDept().getDeptName());
|
}
|
}
|
StateProject projectById = stateProjectService.getProjectById(recordAndItemBO.getProjectId());
|
if (Objects.nonNull(projectById)) {
|
stateApplyRecord.setRecordNo(projectById.getProjectNo());
|
}
|
|
stateApplyRecord.setHouseholdCount((int) recordAndItemBO.getApplyOwnerBOList()
|
.stream()
|
.map(ApplyOwnerBO::getStateHouseholdId).filter(Objects::nonNull).collect(Collectors.toList()).stream()
|
.distinct().count());
|
|
this.saveOrUpdate(stateApplyRecord);
|
|
//发起请款流程
|
ProcessStartBO processStartBO = new ProcessStartBO();
|
if (Objects.equals(ApplyTypeEnum.TEMPORARY_RESIDENTIAL_SUBSIDY.getValue(), recordAndItemBO.getApplyType())) {
|
processStartBO.setCategory(ProcessCategoryEnum.CATEGORY5.getValue().toString());
|
processStartBO.setModuleName("住宅临时安置补助费");
|
} else {
|
processStartBO.setCategory(ProcessCategoryEnum.CATEGORY6.getValue().toString());
|
processStartBO.setModuleName("停产停业经济损失补助费");
|
}
|
|
StateProject stateProject = stateProjectService.getProjectById(stateApplyRecord.getProjectId());
|
String name = ObjectUtil.isEmpty(stateProject) ? "" : stateProject.getProjectName();
|
processStartBO.setName(name);
|
|
//http://122.9.167.128/zentao/bug-view-15459.html
|
//需要显示发起申请人所在单位
|
String cedName = SecurityUtils.getLoginUser().getUser().getDept().getDeptName();
|
String remark = String.format("【镇/街】:%s,【征收实施单位】:%s,【申请金额】:%s万元", stateProject.getStreet(), cedName, stateApplyRecord.getAmount());
|
processStartBO.setRemark(remark);
|
Map<String, Object> variable = new HashMap<>();
|
variable.put("recordId", stateApplyRecord.getId());
|
variable.put("applyId", stateApplyRecord.getId());
|
variable.put("projectId", stateApplyRecord.getProjectId());
|
variable.put("applyType", stateApplyRecord.getApplyType());
|
processStartBO.setVariable(variable);
|
//开启工作流程
|
stateProcessTemplateService.start(processStartBO);
|
|
//保存请款子表
|
newRecordItem.forEach(e -> e.setApplyId(stateApplyRecord.getId()));
|
return stateApplyRecordItemService.saveOrUpdateBatch(newRecordItem);
|
}
|
|
/**
|
* 通过项目id查询权利人
|
* @param getApplyHouseholdOwnerBO
|
* @return
|
*/
|
@Override
|
public ApplyHouseholdOwnerVO getApplyHouseholdOwner(GetApplyHouseholdOwnerBO getApplyHouseholdOwnerBO) {
|
String projectId = getApplyHouseholdOwnerBO.getProjectId();
|
String ownerName = getApplyHouseholdOwnerBO.getOwnerName();
|
String street = getApplyHouseholdOwnerBO.getStreet();
|
|
LambdaQueryWrapper<StateProject> lqwStateProject = new LambdaQueryWrapper<>();
|
lqwStateProject.eq(StateProject::getId, projectId);
|
//查询项目
|
StateProject one = stateProjectService.getOne(lqwStateProject);
|
if (Objects.isNull(one)) {
|
return new ApplyHouseholdOwnerVO();
|
}
|
LambdaQueryWrapper<StateHousehold> lqwHousehold = new LambdaQueryWrapper<>();
|
lqwHousehold.eq(StateHousehold::getStateProjectId, one.getId());
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(street)) {
|
lqwHousehold.like(StateHousehold::getStreet, street);
|
}
|
//查询房产
|
List<StateHousehold> householdList = stateHouseholdService.list(lqwHousehold);
|
if (CollectionUtils.isEmpty(householdList)) {
|
return new ApplyHouseholdOwnerVO();
|
}
|
LambdaQueryWrapper<StateHouseholdOwner> lqwHouseholdOwner = new LambdaQueryWrapper<>();
|
List<String> houseIdList = householdList.stream().map(StateHousehold::getId).collect(Collectors.toList());
|
lqwHouseholdOwner
|
// .eq(StateHouseholdOwner::getOwnerType, ownerType)
|
.in(StateHouseholdOwner::getStateHouseholdId, houseIdList);
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(ownerName)) {
|
lqwHouseholdOwner.like(StateHouseholdOwner::getOwnerName, ownerName);
|
}
|
//查询权利人
|
List<StateHouseholdOwner> ownerList = stateHouseholdOwnerService.list(lqwHouseholdOwner);
|
|
if (CollectionUtils.isEmpty(ownerList)) {
|
return new ApplyHouseholdOwnerVO();
|
}
|
//查询项目关联的补偿标准
|
StateProjectCompensation compensation = stateProjectCompensationService.getById(one.getId());
|
|
Map<String, StateHousehold> stateHouseholdMap = householdList.stream().collect(Collectors.toMap(StateHousehold::getId, Function.identity()));
|
ApplyHouseholdOwnerVO applyHouseholdOwnerVO = new ApplyHouseholdOwnerVO();
|
applyHouseholdOwnerVO.setProjectName(one.getProjectName());
|
applyHouseholdOwnerVO.setProjectStartTime(one.getStartTime());
|
|
|
if (Objects.nonNull(compensation)) {
|
applyHouseholdOwnerVO.setTransitionFeeStandardName(compensation.getPolicySubsidy());
|
Integer status = 0;
|
if (ApplyTypeEnum.TEMPORARY_RESIDENTIAL_SUBSIDY.getValue().equals(getApplyHouseholdOwnerBO.getApplyType())) {
|
status = CompensationCategoryEnum.TEMPORARY_HOUSING_ALLOWANCE.getCode();
|
} else if (ApplyTypeEnum.BUSINESS_SHUTDOWN_SUBSIDY.getValue().equals(getApplyHouseholdOwnerBO.getApplyType())) {
|
status = CompensationCategoryEnum.NON_RESIDENTIAL_ECONOMIC_LOSS_ALLOWANCE.getCode();
|
}
|
LambdaQueryWrapper<StateProjectCompensateStandard> lqwCompensateStandard = new LambdaQueryWrapper<>();
|
lqwCompensateStandard.eq(StateProjectCompensateStandard::getStandardName, compensation.getPolicySubsidy())
|
.eq(StateProjectCompensateStandard::getCategory, status)
|
.eq(StateProjectCompensateStandard::getCompensateType, CompensateTypeEnum.POLICY_SUBSIDY_FEE.getCode());
|
//查询项目补偿标准
|
List<StateProjectCompensateStandard> list = stateProjectCompensateStandardService.list(lqwCompensateStandard);
|
if (!CollectionUtils.isEmpty(list)) {
|
StateProjectCompensateStandard stateProjectCompensateStandard = list.stream().findFirst().get();
|
applyHouseholdOwnerVO.setDistributionStandard(stateProjectCompensateStandard.getCompensateStandard());
|
applyHouseholdOwnerVO.setUnit(stateProjectCompensateStandard.getUnit());
|
}
|
}
|
ownerList.sort(Comparator.comparing(BaseEntity::getCreateTime));
|
List<ApplyOwnerBO> applyOwnerBOList = StateProjectConvert.INSTANCE.toApplyOwnerBOList(ownerList);
|
Map<String, List<ApplyOwnerBO>> collect = applyOwnerBOList.stream().collect(Collectors.groupingBy(ApplyOwnerBO::getStateHouseholdId));
|
applyOwnerBOList.forEach(e -> {
|
StateHousehold stateHousehold = stateHouseholdMap.get(e.getStateHouseholdId());
|
if (Objects.nonNull(stateHousehold)) {
|
e.setStreet(stateHousehold.getStreet());
|
e.setRealEstateCertificateNumber(stateHousehold.getRealEstateCertificateNumber());
|
}
|
});
|
List<ApplyOwnerBO> newList = new ArrayList<>();
|
collect.forEach((k, v) -> {
|
ApplyOwnerBO applyOwnerBO = v.get(0);
|
applyOwnerBO.setOwnerName(v.stream().map(ApplyOwnerBO::getOwnerName).collect(Collectors.joining("|")));
|
applyOwnerBO.setStateHouseholdOwnerId(v.stream().map(ApplyOwnerBO::getStateHouseholdOwnerId).collect(Collectors.joining("|")));
|
StateHousehold stateHousehold = stateHouseholdMap.get(applyOwnerBO.getStateHouseholdId());
|
if (Objects.nonNull(stateHousehold)) {
|
applyOwnerBO.setStreet(stateHousehold.getStreet());
|
applyOwnerBO.setRealEstateCertificateNumber(stateHousehold.getRealEstateCertificateNumber());
|
}
|
newList.add(applyOwnerBO);
|
});
|
newList.sort(Comparator.comparing(ApplyOwnerBO::getRealEstateCertificateNumber));
|
applyHouseholdOwnerVO.setApplyOwnerBOList(newList);
|
return applyHouseholdOwnerVO;
|
}
|
|
/**
|
* 分页查询一级台账
|
* @param stateApplyRecordPageBO
|
* @return
|
*/
|
@Override
|
public StateApplyRecordPageInfoLevelVO pageInfoLevel(StateApplyRecordPageInfoLevelBO stateApplyRecordPageBO) {
|
List<StateApplyRecordVO> allStateApplyRecordVOList = this.getBaseMapper().selectApplyRecordWithProject(stateApplyRecordPageBO);
|
if (CollectionUtils.isEmpty(allStateApplyRecordVOList)) {
|
return new StateApplyRecordPageInfoLevelVO();
|
}
|
StateApplyRecordPageInfoLevelVO vo = new StateApplyRecordPageInfoLevelVO();
|
int totalCount = allStateApplyRecordVOList.stream().mapToInt(StateApplyRecord::getHouseholdCount).sum();
|
BigDecimal totalAmount = allStateApplyRecordVOList.stream()
|
.filter(Objects::nonNull)
|
.filter(data -> Objects.nonNull(data.getAmount()) && data.getApplyType().equals(stateApplyRecordPageBO.getApplyType()))
|
.map(StateApplyRecord::getAmount) // 将 mapToInt 替换为 map 以处理 BigDecimal
|
.reduce(BigDecimal.ZERO, BigDecimal::add); // 使用 reduce 方法累加
|
|
vo.setTotalCount(totalCount);
|
|
// 使用 BigDecimal 进行除法并转换为字符串,保留 "万" 的单位
|
vo.setTotalAmount(totalAmount.setScale(4, BigDecimal.ROUND_HALF_UP) + "万");
|
|
PageUtils.startPage();
|
List<StateApplyRecordVO> stateApplyRecordVOS = this.getBaseMapper().selectApplyRecordWithProject(stateApplyRecordPageBO);
|
if (CollectionUtils.isEmpty(stateApplyRecordVOS)) {
|
return vo;
|
}
|
PageInfo<StateApplyRecordVO> stateApplyRecordVOPageInfo = new PageInfo<>(stateApplyRecordVOS);
|
List<String> projectIdList = stateApplyRecordVOPageInfo.getList().stream().map(StateApplyRecordVO::getProjectId).collect(Collectors.toList());
|
|
Map<String, StateProjectCompensateStandard> projectCompensationStandardMap = getProjectCompensationStandardMap(projectIdList);
|
|
stateApplyRecordVOS.forEach(e -> {
|
StateProjectCompensateStandard compensationStandard = projectCompensationStandardMap.get(e.getProjectId());
|
if (Objects.nonNull(compensationStandard)) {
|
e.setTransitionFee(compensationStandard.getCompensateStandard());
|
e.setUnit(compensationStandard.getUnit());
|
}
|
if (Objects.nonNull(e.getTransitionFeeStartDate()) && Objects.nonNull(e.getTransitionFeeEndDate())) {
|
int i = DateUtils.differentMonthsByDate(e.getTransitionFeeStartDate(), e.getTransitionFeeEndDate());
|
e.setDistributionMonths(i);
|
}
|
});
|
stateApplyRecordVOS.sort(Comparator.comparing(BaseEntity::getCreateTime));
|
stateApplyRecordVOPageInfo.setList(stateApplyRecordVOS);
|
vo.setPageInfo(stateApplyRecordVOPageInfo);
|
return vo;
|
}
|
|
private Map<String, StateProjectCompensateStandard> getProjectCompensationStandardMap(List<String> projectIdList) {
|
// 查询项目的补偿信息
|
LambdaQueryWrapper<StateProjectCompensation> lqwCompensate = new LambdaQueryWrapper<>();
|
lqwCompensate.in(StateProjectCompensation::getProjectId, projectIdList);
|
List<StateProjectCompensation> compensationList = stateProjectCompensationService.list(lqwCompensate);
|
|
if (CollectionUtils.isEmpty(compensationList)) {
|
return new HashMap<>();
|
}
|
|
// 根据补偿信息查询对应的补偿标准
|
List<String> policySubsidyList = compensationList.stream()
|
.map(StateProjectCompensation::getPolicySubsidy)
|
.collect(Collectors.toList());
|
|
LambdaQueryWrapper<StateProjectCompensateStandard> lqwCompensateStandard = new LambdaQueryWrapper<>();
|
lqwCompensateStandard.in(StateProjectCompensateStandard::getStandardName, policySubsidyList)
|
.eq(StateProjectCompensateStandard::getCategory, CompensationCategoryEnum.TEMPORARY_HOUSING_ALLOWANCE.getCode())
|
.eq(StateProjectCompensateStandard::getCompensateType, CompensateTypeEnum.POLICY_SUBSIDY_FEE.getCode());
|
|
List<StateProjectCompensateStandard> standardList = stateProjectCompensateStandardService.list(lqwCompensateStandard);
|
|
// 生成项目ID到补偿标准的映射表
|
return compensationList.stream().collect(Collectors.toMap(
|
StateProjectCompensation::getProjectId,
|
compensation -> {
|
Optional<StateProjectCompensateStandard> standardOpt = standardList.stream()
|
.filter(standard -> standard.getStandardName().equals(compensation.getPolicySubsidy()))
|
.findFirst();
|
return standardOpt.get();
|
}
|
));
|
}
|
|
/**
|
* 住宅临时安置补助费户详情或者 或者 停产停业补助费详情
|
* @param getApplyHouseholdOwnerBO
|
* @return
|
*/
|
@Override
|
public PageInfo<ApplyOwnerBO> getApplyHouseholdOwnerInfo(GetApplyHouseholdOwnerBO getApplyHouseholdOwnerBO) {
|
PageUtils.startPage();
|
//TODO 查询请款记录 由于之前产品设计的问题是以权利人作为维度的即一个请款对应是 一个权利人, 后期又修改成了 以房产为 维度 即一个请款对应一个房产 导致之前数据库设计有问题
|
List<ApplyOwnerBO> applyHouseholdOwnerVOS = this.getBaseMapper().selectApplyRecordWithOwnerDistinctPage(getApplyHouseholdOwnerBO);
|
|
if (CollectionUtils.isEmpty(applyHouseholdOwnerVOS)) {
|
return new PageInfo<>();
|
}
|
getApplyHouseholdOwnerBO.setStateHouseIdList(applyHouseholdOwnerVOS.stream().map(ApplyOwnerBO::getStateHouseholdId).collect(Collectors.toList()));
|
PageInfo<ApplyOwnerBO> applyOwnerBOPageInfo = new PageInfo<>(applyHouseholdOwnerVOS);
|
//TODO
|
List<ApplyOwnerBO> applyOwnerBOS = this.getBaseMapper().selectApplyRecordWithOwnerPage(getApplyHouseholdOwnerBO);
|
applyOwnerBOPageInfo.setList(applyOwnerBOS);
|
List<String> projectIdList = applyOwnerBOPageInfo.getList().stream().map(ApplyOwnerBO::getProjectId).collect(Collectors.toList());
|
|
List<String> houseIdList = applyOwnerBOPageInfo.getList().stream().map(ApplyOwnerBO::getStateHouseholdId).collect(Collectors.toList());
|
List<String> ownerIdList = applyOwnerBOPageInfo.getList().stream().map(ApplyOwnerBO::getStateHouseholdOwnerId).collect(Collectors.toList());
|
|
List<StateHousehold> stateHouseholds = stateHouseholdService.listByIds(houseIdList);
|
Map<String, String> realNumber = stateHouseholds
|
.stream().filter(Objects::nonNull)
|
.collect(Collectors.toMap(StateHousehold::getId, StateHousehold::getRealEstateCertificateNumber));
|
LambdaQueryWrapper<StateApplyRecordItem> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.in(StateApplyRecordItem::getStateHouseholdOwner, ownerIdList);
|
List<StateApplyRecordItem> list = stateApplyRecordItemService.list(queryWrapper);
|
|
|
LambdaQueryWrapper<StateApplyRecord> stateApplyRecordQueryWrapper = new LambdaQueryWrapper<>();
|
// stateApplyRecordQueryWrapper.in(StateApplyRecord::getApplyStatus, SubmitStatusEnum.ACCEPT.getValue());
|
stateApplyRecordQueryWrapper.eq(StateApplyRecord::getApplyType, getApplyHouseholdOwnerBO.getApplyType());
|
List<StateApplyRecord> stateApplyRecordList = stateApplyRecordService.list(stateApplyRecordQueryWrapper);
|
if (!CollectionUtils.isEmpty(stateApplyRecordList)) {
|
list = list.stream().filter(e -> stateApplyRecordList.stream().map(StateApplyRecord::getId).collect(Collectors.toList()).contains(e.getApplyId())).collect(Collectors.toList());
|
}
|
|
|
Map<String, Map<String, List<StateApplyRecordItem>>> itemMap;
|
if (CollectionUtils.isEmpty(list)) {
|
itemMap = new HashMap<>();
|
} else {
|
itemMap = list.stream().collect(Collectors.groupingBy(StateApplyRecordItem::getApplyId, Collectors.groupingBy(StateApplyRecordItem::getStateHouseholdId)));
|
}
|
// List<StateProject> stateProjects = stateProjectService.listByIds(projectIdList);
|
|
// Map<String, StateProject> stateProjectMap = stateProjects.stream().collect(Collectors.toMap(StateProject::getId, Function.identity()));
|
|
Map<String, StateProjectCompensateStandard> projectCompensationStandardMap = getProjectCompensationStandardMap(projectIdList);
|
Map<String, List<ApplyOwnerBO>> stateHouseRecordMap = applyOwnerBOS.stream().collect(Collectors.groupingBy(ApplyOwnerBO::getStateHouseholdId));
|
|
List<ApplyOwnerBO> newList = new ArrayList<>();
|
stateHouseRecordMap.forEach((k, v) -> {
|
ApplyOwnerBO applyOwnerBO = v.get(0);
|
applyOwnerBO.setOwnerName(v.stream().map(ApplyOwnerBO::getOwnerName).collect(Collectors.joining("|")));
|
applyOwnerBO.setStateHouseholdOwnerId(v.stream().map(ApplyOwnerBO::getStateHouseholdOwnerId).collect(Collectors.joining("|")));
|
newList.add(applyOwnerBO);
|
});
|
for (ApplyOwnerBO e : newList) {
|
StateProjectCompensateStandard compensationStandard = projectCompensationStandardMap.get(e.getProjectId());
|
if (Objects.nonNull(compensationStandard)) {
|
e.setTransitionFee(compensationStandard.getCompensateStandard());
|
e.setUnit(compensationStandard.getUnit());
|
}
|
String[] ownerIdArray = e.getStateHouseholdOwnerId().split("\\|");
|
if (0 != ownerIdArray.length) {
|
List<StateApplyRecordItem> stateApplyRecordItems = new ArrayList<>();
|
|
itemMap.forEach((k, v) -> {
|
if (!CollectionUtils.isEmpty(v.get(e.getStateHouseholdId()))) {
|
stateApplyRecordItems.add(v.get(e.getStateHouseholdId()).get(0));
|
}
|
});
|
|
if (!CollectionUtils.isEmpty(stateApplyRecordItems)) {
|
e.setTotalDistributionAmount(String.valueOf(
|
stateApplyRecordItems.stream()
|
.map(item -> new BigDecimal(item.getDistributionAmount())) // 将 String 转为 BigDecimal
|
.reduce(BigDecimal.ZERO, BigDecimal::add) // 求和
|
.setScale(2, RoundingMode.HALF_UP) // 四舍五入保留两位小数
|
));
|
}
|
}
|
//原本原型是已发放月数
|
// if (Objects.nonNull(e.getStartDistributionTime())) {
|
// int i = DateUtils.differentMonthsByDate(e.getStartDistributionTime(), new Date());
|
// e.setAlreadyDistributionMonths(i);
|
// }
|
if (realNumber.containsKey(e.getStateHouseholdId())) {
|
e.setRealEstateCertificateNumber(realNumber.get(e.getStateHouseholdId()));
|
}
|
e.setAlreadyDistributionMonths(Integer.valueOf(e.getDistributionMonths()));
|
|
// if (stateProjectMap.containsKey(e.getProjectId())) {
|
// e.setStreet(stateProjectMap.get(e.getProjectId()).getStreet());
|
// }
|
}
|
applyOwnerBOPageInfo.setList(newList);
|
return applyOwnerBOPageInfo;
|
}
|
|
/**
|
* 任务中心-请帐详情
|
* @param getApplyHouseholdOwnerBO
|
* @return
|
*/
|
@Override
|
public ApplyBO stateApplyRecordDetail(GetApplyHouseholdOwnerBO getApplyHouseholdOwnerBO) {
|
StateApplyRecord stateApplyRecord = this.getById(getApplyHouseholdOwnerBO.getApplyId());
|
if (Objects.isNull(stateApplyRecord)) {
|
return null;
|
}
|
ApplyBO applyBO = BeanUtil.toBean(stateApplyRecord, ApplyBO.class);
|
StateProject stateProject = stateProjectService.getProjectById(stateApplyRecord.getProjectId());
|
if (ObjectUtil.isNotEmpty(stateProject)) {
|
applyBO.setProjectName(stateProject.getProjectName());
|
}
|
return applyBO;
|
}
|
|
/**
|
* 导入权利人
|
* @param importApplyRecordBO
|
* @return
|
*/
|
@Override
|
public List<ApplyOwnerBO> importOwnerByFile(ImportApplyRecordBO importApplyRecordBO) {
|
List<ApplyOwnerVO> dataList;
|
try {
|
dataList = EasyExcelFactory.read(FileUtil.convertToFile(importApplyRecordBO.getFile()))
|
.head(ApplyOwnerVO.class)
|
.sheet()
|
.doReadSync();
|
} catch (IOException e) {
|
throw new GlobalException("读取Excel文件失败");
|
}
|
|
if (CollectionUtils.isEmpty(dataList)) {
|
throw new GlobalException("读取Excel文件失败");
|
}
|
// for (ApplyOwnerVO applyOwnerVO : dataList) {
|
// if (applyOwnerVO.getOwnerName().contains("|")) {
|
// throw new GlobalException("Excel文件不需要带上 | 写全名称,aa | bb 选择其一即可");
|
// }
|
// }
|
LambdaQueryWrapper<StateProject> lqwStateProject = new LambdaQueryWrapper<>();
|
lqwStateProject.eq(StateProject::getId, importApplyRecordBO.getProjectId());
|
StateProject one = stateProjectService.getOne(lqwStateProject);
|
|
if (Objects.isNull(one)) {
|
throw new GlobalException("未查询到相应项目");
|
}
|
//查询项目下的所有房产
|
LambdaQueryWrapper<StateHousehold> lqwHousehold = new LambdaQueryWrapper<>();
|
lqwHousehold.eq(StateHousehold::getStateProjectId, one.getId());
|
|
List<StateHousehold> householdList = stateHouseholdService.list(lqwHousehold);
|
|
if (CollectionUtils.isEmpty(householdList)) {
|
throw new GlobalException("未查询到相应房产");
|
}
|
List<String> realEstateCertificateNumberInDb = householdList.stream().map(StateHousehold::getRealEstateCertificateNumber).collect(Collectors.toList());
|
List<String> realEstateCertificateNumberInExcel = dataList.stream().map(ApplyOwnerVO::getRealEstateCertificateNumber).collect(Collectors.toList());
|
if (CollectionUtils.isEmpty(realEstateCertificateNumberInExcel)) {
|
throw new GlobalException("所有不动产号都为空");
|
}
|
realEstateCertificateNumberInExcel.removeAll(realEstateCertificateNumberInDb);
|
if (!CollectionUtils.isEmpty(realEstateCertificateNumberInExcel)) {
|
String number = realEstateCertificateNumberInExcel.stream().collect(Collectors.joining(","));
|
throw new GlobalException(String.format("这些不动产号不存在:%s", number));
|
}
|
|
LambdaQueryWrapper<StateHouseholdOwner> lqwHouseholdOwner = new LambdaQueryWrapper<>();
|
List<String> houseIdList = householdList.stream().map(StateHousehold::getId).collect(Collectors.toList());
|
lqwHouseholdOwner.in(StateHouseholdOwner::getStateHouseholdId, houseIdList);
|
|
List<StateHouseholdOwner> ownerList = stateHouseholdOwnerService.list(lqwHouseholdOwner);
|
|
if (CollectionUtils.isEmpty(ownerList)) {
|
throw new GlobalException("未查询到相应房产权利人");
|
}
|
|
//TODO 废弃代码开始
|
StateApplyRecord stateApplyRecord;
|
if (org.apache.commons.lang3.StringUtils.isBlank(importApplyRecordBO.getApplyId())) {
|
stateApplyRecord = new StateApplyRecord();
|
stateApplyRecord.setApplyType(importApplyRecordBO.getApplyType());
|
stateApplyRecord.setApplyStatus(SubmitStatusEnum.PENDING_REVIEW.getValue());
|
stateApplyRecord.setProjectId(importApplyRecordBO.getProjectId());
|
stateApplyRecord.setAmount(importApplyRecordBO.getAppliedAmount());
|
stateApplyRecord.setRecordNo(one.getProjectNo());
|
stateApplyRecord.setTransitionFeeEndDate(importApplyRecordBO.getTransitionFeeEndDate());
|
if (SecurityUtils.getLoginUser() != null && SecurityUtils.getLoginUser().getUser() != null) {
|
if (SecurityUtils.getLoginUser().getUser().getNickName() != null) {
|
stateApplyRecord.setApplyUser(SecurityUtils.getLoginUser().getUser().getNickName());
|
}
|
|
if (SecurityUtils.getLoginUser().getUser().getDept() != null &&
|
SecurityUtils.getLoginUser().getUser().getDept().getDeptName() != null) {
|
stateApplyRecord.setApplyDepartment(SecurityUtils.getLoginUser().getUser().getDept().getDeptName());
|
}
|
}
|
// this.save(stateApplyRecord);
|
} else {
|
stateApplyRecord = new StateApplyRecord();
|
stateApplyRecord.setId(importApplyRecordBO.getApplyId());
|
}
|
//废弃代码结束
|
List<ApplyOwnerBO> itemList = new ArrayList<>();
|
ApplyOwnerBO applyOwnerBO;
|
StateApplyRecordItem item;
|
//根据导入数据的不动产权证号筛选出同项目下的房产数据
|
List<StateHousehold> stateHouseholds = householdList.stream().filter(e -> dataList.stream().map(ApplyOwnerVO::getRealEstateCertificateNumber)
|
.collect(Collectors.toList()).contains(e.getRealEstateCertificateNumber())).collect(Collectors.toList());
|
ownerList.sort(Comparator.comparing(BaseEntity::getCreateTime));
|
//权利人根据房产id分组
|
Map<String, List<StateHouseholdOwner>> ownerMap = ownerList.stream().collect(Collectors.groupingBy(StateHouseholdOwner::getStateHouseholdId));
|
//导入数据根据不同不动产权证号分组
|
Map<String, List<ApplyOwnerVO>> importMap = dataList.stream().collect(Collectors.groupingBy(ApplyOwnerVO::getRealEstateCertificateNumber));
|
DecimalFormat decimalFormat = new DecimalFormat("##0.####");
|
for (StateHousehold stateHousehold : stateHouseholds) {
|
List<StateHouseholdOwner> owners = ownerMap.get(stateHousehold.getId());
|
if (!CollectionUtils.isEmpty(owners)) {
|
applyOwnerBO = StateProjectConvert.INSTANCE.toApplyOwnerBO(owners.get(0));//TODO 对象拷贝时new 了对象的
|
applyOwnerBO.setOwnerName(owners.stream().map(StateHouseholdOwner::getOwnerName).collect(Collectors.joining("|"))); // 多个权利人用|分割
|
applyOwnerBO.setStateHouseholdOwnerId(owners.stream().map(StateHouseholdOwner::getId).collect(Collectors.joining("|"))); //多个权利人id以|分割
|
|
applyOwnerBO.setStreet(stateHousehold.getStreet());
|
applyOwnerBO.setRealEstateCertificateNumber(stateHousehold.getRealEstateCertificateNumber());
|
List<ApplyOwnerVO> applyOwnerVOS = importMap.get(applyOwnerBO.getRealEstateCertificateNumber());
|
if (!CollectionUtils.isEmpty(applyOwnerVOS)) {
|
applyOwnerBO.setStartDistributionTime(applyOwnerVOS.get(0).getStartDistributionTime());
|
applyOwnerBO.setEstimatedEndDistributionTime(applyOwnerVOS.get(0).getEstimatedEndDistributionTime());
|
applyOwnerBO.setDistributionMonths(String.valueOf((int) Double.parseDouble(applyOwnerVOS.get(0).getDistributionMonths())));
|
applyOwnerBO.setDistributionAmount(decimalFormat.format(new BigDecimal(applyOwnerVOS.get(0).getDistributionAmount())));
|
applyOwnerBO.setAdditionalDistributionDays(String.valueOf((int) Double.parseDouble(applyOwnerVOS.get(0).getAdditionalDistributionDays())));
|
}
|
itemList.add(applyOwnerBO);
|
|
}
|
}
|
|
// Map<String, List<ApplyOwnerVO>> dataMap = itemList.stream().collect(Collectors.groupingBy());
|
// stateApplyRecordItemService.saveBatch(itemList);
|
itemList.sort(Comparator.comparing(ApplyOwnerBO::getRealEstateCertificateNumber));
|
return itemList;
|
}
|
|
@Override
|
public void updateApplyStatus(String recordId, Integer status) {
|
LambdaUpdateWrapper<StateApplyRecord> updateWrapper = new LambdaUpdateWrapper<>();
|
updateWrapper.eq(StateApplyRecord::getId, recordId)
|
.set(StateApplyRecord::getApplyStatus, status);
|
this.update(updateWrapper);
|
}
|
}
|