|
|
|
@ -93,26 +93,31 @@ public class HouseResidentServiceImpl extends BaseServiceImpl<HouseResidentDao, |
|
|
|
|
|
|
|
@Override |
|
|
|
public PopulationInformationDTO get(String id) { |
|
|
|
PopulationInformationDTO populationInformationDTO = baseDao.selectByHouseId(id); |
|
|
|
PopulationInformationDTO populationInformationDTO = baseDao.selectByHouseResidentId(id); |
|
|
|
return populationInformationDTO; |
|
|
|
} |
|
|
|
/** 居住人的新增和更新逻辑: |
|
|
|
* 新增:1.判断填写的身份证是否已存在 |
|
|
|
* 不存在:直接新增人口信息和关联表信息 |
|
|
|
* 存在:更新原有的人口信息和关联信息 |
|
|
|
* 存在:更新原有的人口信息和关联信息(若是有户主身份,且在此是第一次新增居住信息,则直接更新原有人口信息和新增关联信息) |
|
|
|
* 更新:1.若是身份证被修改:判断填写的身份证是否存在 |
|
|
|
* 不存在:代表更新关联表信息和新增人口信息,原先的人口信息如果只有居住人身份的话则直接删除 |
|
|
|
* ****存在(只有人才才会走到这个逻辑): |
|
|
|
* 1.判断修改的身份证信息是不是在当前房屋下,存在则返回错误信息 |
|
|
|
* 2.不在此房屋下: |
|
|
|
* 更新原先关联关系为表单的身份证和表单房子关联 |
|
|
|
* 更新原先的人口信息 |
|
|
|
* 删除被更新的人口信息(非户主)和人口关系 |
|
|
|
* 若是此身份证有户主身份: |
|
|
|
* (1)更新原先的人口信息 |
|
|
|
* (2)新增居民关联关系为表单的身份证和表单房子关联 |
|
|
|
* (3)删除被更新的人口信息(非户主)和人口关系 |
|
|
|
* 若是此身份证有居住人身份(或者既有户主又有居民身份): |
|
|
|
* (1)更新原先居民关联关系为表单的身份证和表单房子关联 |
|
|
|
* (2)更新原先的人口信息 |
|
|
|
* (3)删除被更新的人口信息(非户主)和人口关系 |
|
|
|
* |
|
|
|
* */ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result save(HouseResidentDTO dto) { |
|
|
|
public Result saveWithIdentifyNo(HouseResidentDTO dto) { |
|
|
|
//先判断身份证是否合法
|
|
|
|
String result = IdentityNoUtils.IdentityNoVerification(dto.getResidentsIdentityNo()); |
|
|
|
if(result != null){ |
|
|
|
@ -122,8 +127,6 @@ public class HouseResidentServiceImpl extends BaseServiceImpl<HouseResidentDao, |
|
|
|
String birthday = IdentityNoUtils.getBirthday(dto.getResidentsIdentityNo()); |
|
|
|
//根据身份证查询新人口信息
|
|
|
|
PopulationInformationEntity newPopulationInformationEntity = populationInformationService.getInfoByIdentityNo(dto.getResidentsIdentityNo()); |
|
|
|
//查询新的房屋的信息 - 赋值房子所在网格
|
|
|
|
HousingInformationEntity housingInformationEntity = housingInformationService.selectById(dto.getHouseId()); |
|
|
|
if(newPopulationInformationEntity==null){ |
|
|
|
newPopulationInformationEntity = new PopulationInformationEntity(); |
|
|
|
newPopulationInformationEntity.setResidentsName(dto.getResidentsName()); |
|
|
|
@ -136,11 +139,6 @@ public class HouseResidentServiceImpl extends BaseServiceImpl<HouseResidentDao, |
|
|
|
newPopulationInformationEntity.setCurrentAddress(dto.getCurrentAddress()); |
|
|
|
newPopulationInformationEntity.setResidentsSex(sex); |
|
|
|
newPopulationInformationEntity.setResidentsBirthday(DateUtil.parse(birthday)); |
|
|
|
newPopulationInformationEntity.setGridId(housingInformationEntity.getGridId()); |
|
|
|
newPopulationInformationEntity.setAllDeptIds(housingInformationEntity.getAllDeptIds()); |
|
|
|
newPopulationInformationEntity.setAllDeptNames(housingInformationEntity.getAllDeptNames()); |
|
|
|
newPopulationInformationEntity.setParentDeptIds(housingInformationEntity.getParentDeptIds()); |
|
|
|
newPopulationInformationEntity.setParentDeptNames(housingInformationEntity.getParentDeptNames()); |
|
|
|
//插入人口信息
|
|
|
|
populationInformationService.insert(newPopulationInformationEntity); |
|
|
|
//插入关联表信息
|
|
|
|
@ -152,11 +150,32 @@ public class HouseResidentServiceImpl extends BaseServiceImpl<HouseResidentDao, |
|
|
|
insert(entity); |
|
|
|
}else if(newPopulationInformationEntity!=null){ |
|
|
|
//人口信息不是空,则新人口信息转变为旧人口信息
|
|
|
|
//查询表单身份证的人口的和房子的关联关系
|
|
|
|
//1.查询表单身份证的人口的和房子的关联关系(查询条件是非户主身份的)
|
|
|
|
HouseResidentEntity oldHouseResidentEntity = baseDao.getHouseResidentInfoByResidentId(newPopulationInformationEntity.getId()); |
|
|
|
//查询表单身份证的人口的房子的信息
|
|
|
|
if(oldHouseResidentEntity==null){ |
|
|
|
//此时说明此人有户主身份,则直接更新人口信息和新增关联信息
|
|
|
|
newPopulationInformationEntity.setResidentsName(dto.getResidentsName()); |
|
|
|
newPopulationInformationEntity.setResidentsNation(dto.getResidentsNation()); |
|
|
|
newPopulationInformationEntity.setEducationLevel(dto.getEducationLevel()); |
|
|
|
newPopulationInformationEntity.setPoliticsStatus(dto.getPoliticsStatus()); |
|
|
|
newPopulationInformationEntity.setResidentsIdentityNo(dto.getResidentsIdentityNo()); |
|
|
|
newPopulationInformationEntity.setResidentsPhone(dto.getResidentsPhone()); |
|
|
|
newPopulationInformationEntity.setCurrentEmployer(dto.getCurrentEmployer()); |
|
|
|
newPopulationInformationEntity.setCurrentAddress(dto.getCurrentAddress()); |
|
|
|
newPopulationInformationEntity.setResidentsSex(sex); |
|
|
|
newPopulationInformationEntity.setResidentsBirthday(DateUtil.parse(birthday)); |
|
|
|
//更新人口信息
|
|
|
|
populationInformationService.updateById(newPopulationInformationEntity); |
|
|
|
//新增关联表信息为当前房屋
|
|
|
|
oldHouseResidentEntity.setHouseId(dto.getHouseId()); |
|
|
|
oldHouseResidentEntity.setHouseHeadRelation(dto.getHouseHeadRelation()); |
|
|
|
oldHouseResidentEntity.setResidentId(newPopulationInformationEntity.getId()); |
|
|
|
insert(oldHouseResidentEntity); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
//2.查询表单身份证的人口的房子的信息
|
|
|
|
HousingInformationEntity oldHousingInformationEntity = housingInformationService.selectById(oldHouseResidentEntity.getHouseId()); |
|
|
|
//第一次修改
|
|
|
|
//3.第一次修改
|
|
|
|
//比较当前房屋和表单身份证的旧房屋信息
|
|
|
|
//如果不同则提示是否要进行修改
|
|
|
|
if("0".equals(dto.getIsEditResidentInfo()) && !dto.getHouseId().equals(oldHouseResidentEntity.getHouseId())){ |
|
|
|
@ -172,11 +191,6 @@ public class HouseResidentServiceImpl extends BaseServiceImpl<HouseResidentDao, |
|
|
|
newPopulationInformationEntity.setCurrentAddress(dto.getCurrentAddress()); |
|
|
|
newPopulationInformationEntity.setResidentsSex(sex); |
|
|
|
newPopulationInformationEntity.setResidentsBirthday(DateUtil.parse(birthday)); |
|
|
|
newPopulationInformationEntity.setGridId(housingInformationEntity.getGridId()); |
|
|
|
newPopulationInformationEntity.setAllDeptIds(housingInformationEntity.getAllDeptIds()); |
|
|
|
newPopulationInformationEntity.setAllDeptNames(housingInformationEntity.getAllDeptNames()); |
|
|
|
newPopulationInformationEntity.setParentDeptIds(housingInformationEntity.getParentDeptIds()); |
|
|
|
newPopulationInformationEntity.setParentDeptNames(housingInformationEntity.getParentDeptNames()); |
|
|
|
//更新人口信息
|
|
|
|
populationInformationService.updateById(newPopulationInformationEntity); |
|
|
|
//更新旧的关联表信息为当前房屋
|
|
|
|
@ -195,7 +209,7 @@ public class HouseResidentServiceImpl extends BaseServiceImpl<HouseResidentDao, |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result update(HouseResidentDTO dto) { |
|
|
|
public Result updateWithIdentifyNo(HouseResidentDTO dto) { |
|
|
|
//判断身份证是否发生修改
|
|
|
|
HouseResidentEntity oldHouseResident = baseDao.selectById(dto.getId()); |
|
|
|
PopulationInformationEntity oldPopulationInformation = populationInformationService.selectById(oldHouseResident.getResidentId()); |
|
|
|
@ -224,8 +238,6 @@ public class HouseResidentServiceImpl extends BaseServiceImpl<HouseResidentDao, |
|
|
|
//根据身份证判断此人是否已有居住信息
|
|
|
|
//新的居住人信息
|
|
|
|
PopulationInformationEntity populationInformationEntity = populationInformationService.getInfoByIdentityNo(dto.getResidentsIdentityNo()); |
|
|
|
//新的房子信息
|
|
|
|
HousingInformationEntity housingInformationEntity = housingInformationService.selectById(dto.getHouseId()); |
|
|
|
if(populationInformationEntity==null){ |
|
|
|
//新的居住人信息是空,代表添加新的人口信息到表中。并且由于此处是更新,则当前选择的被更新人的数据要从人口信息表中删除,且之前的关联关系也得更新
|
|
|
|
populationInformationEntity = new PopulationInformationEntity(); |
|
|
|
@ -239,11 +251,6 @@ public class HouseResidentServiceImpl extends BaseServiceImpl<HouseResidentDao, |
|
|
|
populationInformationEntity.setCurrentAddress(dto.getCurrentAddress()); |
|
|
|
populationInformationEntity.setResidentsSex(sex); |
|
|
|
populationInformationEntity.setResidentsBirthday(DateUtil.parse(birthday)); |
|
|
|
populationInformationEntity.setGridId(housingInformationEntity.getGridId()); |
|
|
|
populationInformationEntity.setAllDeptIds(housingInformationEntity.getAllDeptIds()); |
|
|
|
populationInformationEntity.setAllDeptNames(housingInformationEntity.getAllDeptNames()); |
|
|
|
populationInformationEntity.setParentDeptIds(housingInformationEntity.getParentDeptIds()); |
|
|
|
populationInformationEntity.setParentDeptNames(housingInformationEntity.getParentDeptNames()); |
|
|
|
//获取原先关联表信息
|
|
|
|
HouseResidentEntity entity = selectById(dto.getId()); |
|
|
|
//查询原先绑定的居住人的信息,如果此居住人只有居住人身份则删除此人人口信息
|
|
|
|
@ -282,11 +289,6 @@ public class HouseResidentServiceImpl extends BaseServiceImpl<HouseResidentDao, |
|
|
|
populationInformationEntity.setResidentsPhone(dto.getResidentsPhone()); |
|
|
|
populationInformationEntity.setCurrentEmployer(dto.getCurrentEmployer()); |
|
|
|
populationInformationEntity.setCurrentAddress(dto.getCurrentAddress()); |
|
|
|
populationInformationEntity.setGridId(housingInformationEntity.getGridId()); |
|
|
|
populationInformationEntity.setAllDeptIds(housingInformationEntity.getAllDeptIds()); |
|
|
|
populationInformationEntity.setAllDeptNames(housingInformationEntity.getAllDeptNames()); |
|
|
|
populationInformationEntity.setParentDeptIds(housingInformationEntity.getParentDeptIds()); |
|
|
|
populationInformationEntity.setParentDeptNames(housingInformationEntity.getParentDeptNames()); |
|
|
|
//(2)删除被更新的人的人口信息和关联信息 - 组装信息
|
|
|
|
//获取原先关联表信息
|
|
|
|
HouseResidentEntity entity = selectById(dto.getId()); |
|
|
|
@ -295,19 +297,24 @@ public class HouseResidentServiceImpl extends BaseServiceImpl<HouseResidentDao, |
|
|
|
oldParams.put("RESIDENT_ID",entity.getResidentId()); |
|
|
|
oldParams.put("IS_HOUSE_HEAD","0"); |
|
|
|
List<HouseResidentEntity> oldHouseResidentEntities = baseDao.selectByMap(oldParams); |
|
|
|
//(3)更新表单身份证与房屋关联关系为当前房屋
|
|
|
|
//(3)更新表单身份证与房屋关联关系为当前房屋(若是表单身份证存在户主身份,且第一次添加居住人,则新增关联关系)
|
|
|
|
//获取表单身份证之前的居住地关联关系表的信息
|
|
|
|
HouseResidentEntity newHouseResidentEntity = houseResidentDao.getHouseResidentInfoByResidentId(populationInformationEntity.getId()); |
|
|
|
if(newHouseResidentEntity==null){ |
|
|
|
//此处判断代表此人有户主身份,且第一次更新为居民身份,此时新增关联关系
|
|
|
|
newHouseResidentEntity.setHouseId(dto.getHouseId()); |
|
|
|
newHouseResidentEntity.setHouseHeadRelation(dto.getHouseHeadRelation()); |
|
|
|
// (4)进行修改!
|
|
|
|
newHouseResidentEntity.setResidentId(populationInformationEntity.getId()); |
|
|
|
houseResidentDao.insert(newHouseResidentEntity); |
|
|
|
}else { |
|
|
|
houseResidentDao.updateById(newHouseResidentEntity); |
|
|
|
} |
|
|
|
baseDao.deleteById(entity.getId()); |
|
|
|
if(oldHouseResidentEntities!=null && oldHouseResidentEntities.size()>0){ |
|
|
|
//没有户主身份,删除人口信息
|
|
|
|
populationInformationService.deleteById(entity.getResidentId()); |
|
|
|
} |
|
|
|
|
|
|
|
houseResidentDao.updateById(newHouseResidentEntity); |
|
|
|
populationInformationService.updateById(populationInformationEntity); |
|
|
|
}else { |
|
|
|
return new Result().error("参数传递出错"); |
|
|
|
@ -330,4 +337,29 @@ public class HouseResidentServiceImpl extends BaseServiceImpl<HouseResidentDao, |
|
|
|
return new PageData<>(list, page.getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result saveWithoutIdentifyNo(HouseResidentDTO dto) { |
|
|
|
PopulationInformationEntity populationInformationEntity = ConvertUtils.sourceToTarget(dto,PopulationInformationEntity.class); |
|
|
|
populationInformationService.insert(populationInformationEntity); |
|
|
|
HouseResidentEntity houseResidentEntity = ConvertUtils.sourceToTarget(dto,HouseResidentEntity.class); |
|
|
|
houseResidentEntity.setResidentId(populationInformationEntity.getId()); |
|
|
|
houseResidentEntity.setIsHouseHead("0"); |
|
|
|
this.insert(houseResidentEntity); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result updateWithoutIdentifyNo(HouseResidentDTO dto) { |
|
|
|
PopulationInformationEntity populationInformationEntity = populationInformationService.selectById(dto.getResidentId()); |
|
|
|
populationInformationEntity.setResidentsName(dto.getResidentsName()); |
|
|
|
populationInformationEntity.setResidentsSex(dto.getResidentsSex()); |
|
|
|
populationInformationEntity.setResidentsNation(dto.getResidentsNation()); |
|
|
|
populationInformationEntity.setCurrentEmployer(dto.getCurrentEmployer()); |
|
|
|
populationInformationEntity.setCurrentAddress(dto.getCurrentAddress()); |
|
|
|
populationInformationService.updateById(populationInformationEntity); |
|
|
|
HouseResidentEntity houseResidentEntity = ConvertUtils.sourceToTarget(dto,HouseResidentEntity.class); |
|
|
|
this.updateById(houseResidentEntity); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
} |