package com.ruoyi.bussiness.service.impl;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.util.ObjUtil;
|
import com.alibaba.excel.EasyExcelFactory;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.bussiness.domain.Placement;
|
import com.ruoyi.bussiness.domain.PlacementBatchHousehold;
|
import com.ruoyi.bussiness.mapper.PlacementMapper;
|
import com.ruoyi.bussiness.object.request.placement.PlacementIdRequest;
|
import com.ruoyi.bussiness.object.request.placement.PlacementImportRequest;
|
import com.ruoyi.bussiness.object.request.placement.PlacementPageRequest;
|
import com.ruoyi.bussiness.object.response.placement.GetHouseHistoryRequest;
|
import com.ruoyi.bussiness.object.response.placement.PlacementPageResponse;
|
import com.ruoyi.bussiness.object.response.placement.PlacementTemplateResponse;
|
import com.ruoyi.bussiness.service.PlacementBatchHouseholdService;
|
import com.ruoyi.bussiness.service.PlacementService;
|
import com.ruoyi.common.exception.GlobalException;
|
import com.ruoyi.common.utils.file.FileUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
|
import java.io.File;
|
import java.io.IOException;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class PlacementServiceImpl extends ServiceImpl<PlacementMapper, Placement> implements PlacementService {
|
|
@Lazy
|
@Autowired
|
private PlacementBatchHouseholdService placementBatchHouseholdService;
|
|
@Override
|
public PlacementPageResponse page(PlacementPageRequest request) {
|
Page<Placement> page = new Page<>(request.getPageNum(), request.getPageSize());
|
LambdaQueryWrapper<Placement> queryWrapper = new LambdaQueryWrapper<>();
|
if(ObjUtil.isNotEmpty(request.getStreet())){
|
queryWrapper.like(Placement::getStreet,request.getStreet());
|
}
|
if(ObjUtil.isNotEmpty(request.getProjectName())){
|
queryWrapper.like(Placement::getProjectName,request.getProjectName());
|
}
|
if(ObjUtil.isNotEmpty(request.getCommunity())){
|
queryWrapper.like(Placement::getCommunity,request.getCommunity());
|
}
|
if(ObjUtil.isNotEmpty(request.getHeadOrIdCard())){
|
queryWrapper.and(query->query.like(Placement::getHouseholdHead,request.getHeadOrIdCard()).or().like(Placement::getIdCard,request.getHeadOrIdCard()));
|
}
|
if(ObjUtil.isNotEmpty(request.getStatus())){
|
queryWrapper.eq(Placement::getStatus,request.getStatus());
|
}
|
if(ObjUtil.isNotEmpty(request.getFamilyNames())){
|
queryWrapper.like(Placement::getFamilyName,request.getFamilyNames());
|
}
|
Page<Placement> pageResponse = this.baseMapper.selectPage(page, queryWrapper);
|
PlacementPageResponse response = new PlacementPageResponse();
|
response.setTotal(pageResponse.getTotal());
|
response.setRecords(pageResponse.getRecords());
|
return response;
|
}
|
|
@Override
|
public void add(Placement placement) {
|
//查询是否唯一
|
int i = this.countPlacementByFamilyIdCard(placement.getFamilyIdCard());
|
if (i > 1) {
|
throw new GlobalException(placement.getFamilyIdCard() + "家庭成员身份证号已存在!");
|
}
|
this.save(placement);
|
}
|
|
@Override
|
public void update(Placement placement) {
|
LambdaQueryWrapper<Placement> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(Placement::getFamilyIdCard, placement.getFamilyIdCard());
|
queryWrapper.ne(Placement::getId,placement.getId());
|
List<Placement> oldPlacements = this.baseMapper.selectList(queryWrapper);
|
if (!oldPlacements.isEmpty()) {
|
throw new GlobalException(placement.getIdCard() + "身份证号已存在!");
|
}
|
this.updateById(placement);
|
}
|
|
@Override
|
public Placement detail(PlacementIdRequest request) {
|
Placement placement = this.baseMapper.selectById(request.getId());
|
GetHouseHistoryRequest getHouseHistoryRequest = new GetHouseHistoryRequest();
|
getHouseHistoryRequest.setFamilyIdCard(placement.getFamilyIdCard());
|
getHouseHistoryRequest.setFamilyName(placement.getFamilyName());
|
List<PlacementBatchHousehold> households = placementBatchHouseholdService.getHouseHistory(getHouseHistoryRequest);
|
placement.setHouseholds(households);
|
return placement;
|
}
|
|
@Override
|
public void del(PlacementIdRequest request) {
|
this.baseMapper.deleteById(request.getId());
|
}
|
|
@Override
|
public void imports(PlacementImportRequest request) {
|
File file = FileUtils.convertToFile(request.getFile());
|
List<Map<Integer, String>> maps = FileUtils.readExcelHead(file);
|
if (!Objects.equals(maps.get(0).get(0), "项目名称")
|
|| !Objects.equals(maps.get(0).get(1), "项目启动时间")
|
|| !Objects.equals(maps.get(0).get(2), "镇街")
|
|| !Objects.equals(maps.get(0).get(3), "村社区")
|
|| !Objects.equals(maps.get(0).get(4), "组")
|
|| !Objects.equals(maps.get(0).get(5), "户主姓名")
|
|| !Objects.equals(maps.get(0).get(6), "身份证号码")
|
) {
|
throw new GlobalException("Excel表头格式不对");
|
}
|
List<PlacementTemplateResponse> dataList;
|
try {
|
dataList = EasyExcelFactory.read(file)
|
.head(PlacementTemplateResponse.class)
|
.sheet()
|
.doReadSync();
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new GlobalException(e.getMessage());
|
}
|
if (CollectionUtils.isEmpty(dataList)) {
|
throw new GlobalException("未解析出数据");
|
}
|
List<String> idCards = new ArrayList<>();
|
for (PlacementTemplateResponse data : dataList) {
|
if (ObjUtil.isEmpty(data.getIdCard())
|
|| ObjUtil.isEmpty(data.getFamilyIdCard())) {
|
throw new GlobalException("导入数据户主和家庭成员身份证号码不能为空!");
|
}
|
if(ObjUtil.isEmpty(data.getProjectName())){
|
throw new GlobalException("导入数据项目名称不能为空!");
|
}
|
if (ObjUtil.isEmpty(data.getStartTime())) {
|
throw new GlobalException("导入数据项目启动时间不能为空!");
|
}
|
if (ObjUtil.isEmpty(data.getStreet())) {
|
throw new GlobalException("导入数据镇不能为空!");
|
}
|
if (ObjUtil.isEmpty(data.getHouseholdHead())) {
|
throw new GlobalException("导入数据户主不能为空!");
|
}
|
if (ObjUtil.isEmpty(data.getFamilyName())) {
|
throw new GlobalException("导入数据家庭成员不能为空!");
|
}
|
if (ObjUtil.isEmpty(data.getRelation())) {
|
throw new GlobalException("导入数据关系不能为空!");
|
}
|
if (ObjUtil.isEmpty(data.getPersonType())) {
|
throw new GlobalException("导入数据人员性质不能为空!");
|
}
|
|
// if (ObjUtil.isEmpty(data.getAge())) {
|
// throw new GlobalException("导入数据年龄不能为空!");
|
// }
|
// if (ObjUtil.isEmpty(data.getSex())) {
|
// throw new GlobalException("导入数据性别不能为空!");
|
// }
|
// if (ObjUtil.isEmpty(data.getBirthday())) {
|
// throw new GlobalException("导入数据出生年月不能为空!");
|
// }
|
// if (ObjUtil.isEmpty(data.getWays())) {
|
// throw new GlobalException("导入数据安置方式不能为空!");
|
// }
|
// if (ObjUtil.isEmpty(data.getMobile())) {
|
// throw new GlobalException("导入数据联系方式不能为空!");
|
// }
|
// if (ObjUtil.isEmpty(data.getOriginCollectionTime())) {
|
// throw new GlobalException("导入数据原始拆迁过渡时间不能为空!");
|
// }
|
// if (ObjUtil.isEmpty(data.getLastBeginTime())) {
|
// throw new GlobalException("导入数据上次过渡时间不能为空!");
|
// }
|
// if (ObjUtil.isEmpty(data.getLastEndTime())) {
|
// throw new GlobalException("导入数据上次过渡发放时间不能为空!");
|
// }
|
// if (ObjUtil.isEmpty(data.getNoHouseArea())) {
|
// throw new GlobalException("导入数据剩余未安置面积不能为空!");
|
// }
|
// if (ObjUtil.isEmpty(data.getNoShopArea())) {
|
// throw new GlobalException("导入数据剩余未安置商铺面积不能为空!");
|
// }
|
idCards.add(data.getFamilyIdCard());
|
}
|
List<Placement> exists = selectPlacementIdCard(idCards);
|
if (ObjUtil.isNotEmpty(exists)) {
|
String ids = exists.stream().map(Placement::getFamilyIdCard).collect(Collectors.joining(","));
|
throw new GlobalException("身份证已存在:" + ids);
|
}
|
|
List<Placement> placements = BeanUtil.copyToList(dataList, Placement.class);
|
this.saveBatch(placements);
|
}
|
|
@Override
|
public int countPlacementByFamilyIdCard(String familyIdCard) {
|
LambdaQueryWrapper<Placement> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(Placement::getFamilyIdCard,familyIdCard);
|
return this.baseMapper.selectCount(queryWrapper).intValue();
|
}
|
|
@Override
|
public int countPlacementByIdCard(String idCard) {
|
LambdaQueryWrapper<Placement> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(Placement::getIdCard,idCard);
|
return this.baseMapper.selectCount(queryWrapper).intValue();
|
}
|
|
@Override
|
public List<Placement> selectPlacementIdCard(List<String> idCard) {
|
LambdaQueryWrapper<Placement> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.in(Placement::getFamilyIdCard,idCard);
|
return this.baseMapper.selectList(queryWrapper);
|
}
|
|
@Override
|
public int countNamesExists(String name) {
|
LambdaQueryWrapper<Placement> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.in(Placement::getFamilyName,name.trim());
|
return this.baseMapper.selectCount(queryWrapper).intValue();
|
}
|
|
}
|