From f83df1cd20dcab46cd3bf285a3f5a147eb77d5ed Mon Sep 17 00:00:00 2001 From: "java_cuibaocheng@163.com" Date: Mon, 20 Nov 2023 16:15:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=8F=A3=E5=9F=BA=E6=9C=AC=E4=BF=A1?= =?UTF-8?q?=E6=81=AF-=20=E4=BF=AE=E6=94=B9=E5=85=A5=E4=BD=8F=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E7=9A=84=E9=A1=B5=E9=9D=A2=E5=B8=83=E5=B1=80=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=90=8E=E5=8F=B0=E7=9A=84=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/population/PopulationController.java | 17 ++- .../dao/population/IPopulationDao.java | 9 ++ .../service/house/impl/HouseServiceImpl.java | 29 +---- .../population/IPopulationService.java | 16 +++ .../impl/PopulationServiceImpl.java | 85 ++++++++++++++- .../mapper/population/population-mapper.xml | 62 ++++++++++- src/main/resources/templates/house/list.html | 6 +- src/main/resources/templates/house/save.html | 2 +- .../resources/templates/population/list.html | 100 ++++++++++++++---- 9 files changed, 274 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/cm/population/controller/api/population/PopulationController.java b/src/main/java/com/cm/population/controller/api/population/PopulationController.java index 38e07f7..859f304 100644 --- a/src/main/java/com/cm/population/controller/api/population/PopulationController.java +++ b/src/main/java/com/cm/population/controller/api/population/PopulationController.java @@ -36,6 +36,21 @@ public class PopulationController extends AbstractController { @Autowired private IPopulationService populationService; + @ApiOperation(value = "搬离房屋", notes = "搬离房屋") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PutMapping("update-outhouse/{populationIds}") + public SuccessResult updateOuthouse(@PathVariable("populationIds") String populationIds) { + List list = Arrays.asList(populationIds.split("\\_")); + populationService.updateOuthouseTrue(null, list); + return new SuccessResult(); + } + @ApiOperation(value = "新增人房绑定", notes = "新增人房绑定接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("save-all/{houseId}") + public SuccessResult saveList(@PathVariable("houseId") String houseId, @RequestBody List populationVOList) { + populationService.saveAll(null, houseId, populationVOList, false); + return new SuccessResult(); + } @ApiOperation(value = "新增人房绑定", notes = "新增人房绑定接口") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @@ -100,7 +115,7 @@ public class PopulationController extends AbstractController { public SuccessResultList> listPage(ListPage page) { Map params = requestParams(); page.setParams(params); - return populationService.listPage(page); + return populationService.listPageAll(page); } @ApiOperation(value = "人房绑定统计", notes = "人房绑定统计接口") diff --git a/src/main/java/com/cm/population/dao/population/IPopulationDao.java b/src/main/java/com/cm/population/dao/population/IPopulationDao.java index 789db99..05c8e5c 100644 --- a/src/main/java/com/cm/population/dao/population/IPopulationDao.java +++ b/src/main/java/com/cm/population/dao/population/IPopulationDao.java @@ -125,4 +125,13 @@ public interface IPopulationDao { */ void deleteByHouseId(String houseId) throws RemoveException; + /** + * 搬离房屋 + * @param params + */ + void updateOuthouseTrue(Map params); + + List listAll(Map params); + + void updateBindTime(Map params); } \ No newline at end of file diff --git a/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java b/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java index e4ed13c..d1a811a 100644 --- a/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java +++ b/src/main/java/com/cm/population/service/house/impl/HouseServiceImpl.java @@ -94,13 +94,9 @@ public class HouseServiceImpl extends AbstractService implements IHouseService { } houseDao.save(params); - if (!CollectionUtils.isEmpty(houseVO.getPopulationVOList())) { - List populationVOList = houseVO.getPopulationVOList(); - for (PopulationVO populationVO : populationVOList) { - populationVO.setHouseId(houseId); - populationService.saveReturnId(token, populationVO); - } - } + // 2023年11月20日15:38:06 崔宝铖 创建saveAll函数 + populationService.saveAll(token, houseId, houseVO.getPopulationVOList(), true); + return houseId; } @@ -149,24 +145,9 @@ public class HouseServiceImpl extends AbstractService implements IHouseService { } houseDao.update(params); - // 1. 判断创建房屋时,是否有人员信息一起 - // 2. 有的话,删除旧的人员信息,并录入新的人员信息 - if (!CollectionUtils.isEmpty(houseVO.getPopulationVOList())) { - List populationVOList = houseVO.getPopulationVOList(); - for (PopulationVO populationVO : populationVOList) { - if ("1".equals(populationVO.getOutHouse())) { - populationService.update(populationVO.getPopulationId(), populationVO); - } - } + // 2023年11月20日15:38:06 崔宝铖 创建saveAll函数 + populationService.saveAll(token, houseId, houseVO.getPopulationVOList(), true); - populationdao.deleteByHouseId(houseId); - for (PopulationVO populationVO : populationVOList) { - if (!"1".equals(populationVO.getOutHouse())) { - populationVO.setHouseId(houseId); - populationService.save(token, populationVO); - } - } - } } @Override diff --git a/src/main/java/com/cm/population/service/population/IPopulationService.java b/src/main/java/com/cm/population/service/population/IPopulationService.java index 6c4f192..bc26fe3 100644 --- a/src/main/java/com/cm/population/service/population/IPopulationService.java +++ b/src/main/java/com/cm/population/service/population/IPopulationService.java @@ -21,6 +21,17 @@ import java.util.Map; **/ public interface IPopulationService { + /** + * 新增人房绑定 + * 崔宝铖 + * 批量保存更新 + * @param token + * @param houseId + * @param populationVOList + * @param isAllData true:在新增的时候会把旧的全部删除 , false:在新增的时候不会删除旧的数据 + */ + void saveAll(String token, String houseId, List populationVOList, Boolean isAllData); + /** * 新增人房绑定 * @@ -203,5 +214,10 @@ public interface IPopulationService { */ SuccessResultList> findPopulation(ListPage pag); + /** + * 搬离房屋 + */ + void updateOuthouseTrue(String token, List populationIds) ; + SuccessResultList> listPageAll(ListPage page); } \ No newline at end of file diff --git a/src/main/java/com/cm/population/service/population/impl/PopulationServiceImpl.java b/src/main/java/com/cm/population/service/population/impl/PopulationServiceImpl.java index 6235913..a033b28 100644 --- a/src/main/java/com/cm/population/service/population/impl/PopulationServiceImpl.java +++ b/src/main/java/com/cm/population/service/population/impl/PopulationServiceImpl.java @@ -3,6 +3,7 @@ package com.cm.population.service.population.impl; import com.cm.common.base.AbstractService; import com.cm.common.pojo.ListPage; import com.cm.common.result.SuccessResultList; +import com.cm.common.utils.DateUtil; import com.cm.common.utils.HashMapUtil; import com.cm.common.utils.UUIDUtil; import com.cm.population.dao.house.IHouseDao; @@ -26,6 +27,8 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import sun.security.krb5.internal.PAData; import javax.mail.search.SearchException; import java.util.*; @@ -49,6 +52,62 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio @Autowired private IPopulationInfoService populationInfoService; + @Override + public void saveAll(String token, String houseId, List populationVOList, Boolean isAllData) { + // 1. 查出所有当前居住的人员 + Map params = new HashMap<>(); + params.put("houseId", houseId); + params.put("outHouse", "0"); + List list = populationDao.listAll(params); + Map map = new HashMap<>(); + for(PopulationDTO dto : list) { + map.put(dto.getPopulationInfoId(), dto); + } + // 1. 判断创建房屋时,是否有人员信息一起 + // 2. 有的话,删除旧的人员信息,并录入新的人员信息 + if(!CollectionUtils.isEmpty(populationVOList)) { + for (PopulationVO populationVO : populationVOList) { + // 2.将搬离的改掉 + if("1".equals(populationVO.getOutHouse())) { + update(populationVO.getPopulationId(), populationVO); + map.remove(populationVO.getPopulationInfoId()); + } + } + // 记录绑定时间 + for (PopulationVO populationVO : populationVOList) { + PopulationDTO dto = map.get(populationVO.getPopulationInfoId()); + if (dto != null) { + populationVO.setBindTime(dto.getBindTime()); + } + } + // 删除旧的所有的入住信息 + if(isAllData) { + populationDao.deleteByHouseId(houseId); + }else{ + // 剔除已存在的人员的再次新增 + Iterator iterator = populationVOList.iterator(); + while(iterator.hasNext()) { + PopulationVO vo = iterator.next(); + if (map.get(vo.getPopulationInfoId()) != null) { + // 更新绑定事件 + Map update = new HashMap<>(); + update.put("populationId", map.get(vo.getPopulationInfoId()).getPopulationId()); + update.put("bindTime", DateUtil.getTime()); + populationDao.updateBindTime(update); + iterator.remove(); + } + } + } + // 保存新的入住信息 + for (PopulationVO populationVO : populationVOList) { + if(!"1".equals(populationVO.getOutHouse())) { + populationVO.setHouseId(houseId); + save(token, populationVO); + } + } + } + } + @Override public void save(PopulationVO populationVO) { saveReturnId(populationVO); @@ -79,7 +138,7 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio } else { setSaveInfo(token, params); } - params.put("bindTime", params.get("gmtCreate")); + params.put("bindTime", StringUtils.isEmpty(populationVO.getBindTime()) ? params.get("gmtCreate") : populationVO.getBindTime()); params.put("outHouse", 0); // 解除脱敏 @@ -185,7 +244,7 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio @Override public List list(Map params) { List list = populationDao.list(params); - for (PopulationDTO populationDTO : list) { + /* for (PopulationDTO populationDTO : list) { PopulationInfoDTO populationInfoDTO = new PopulationInfoDTO(); if(StringUtils.isNotEmpty(populationDTO.getPopulationInfoId())) { populationInfoDTO = populationInfoService.get(populationDTO.getPopulationInfoId()); @@ -201,7 +260,7 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio populationDTO.setCardNum(populationInfoDTO.getIdcard()); populationDTO.setName(populationInfoDTO.getName()); populationDTO.setPhone(populationInfoDTO.getPhone()); - } + }*/ return list; } @@ -319,4 +378,24 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio return new SuccessResultList<>(overList, pageInfo.getPageNum(), pageInfo.getTotal()); } + @Override + public void updateOuthouseTrue(String token, List populationIds) { + Map params = super.getHashMap(2); + params.put("populationIds", populationIds); + if (StringUtils.isBlank(token)) { + setUpdateInfo(params); + } else { + setUpdateInfo(token, params); + } + populationDao.updateOuthouseTrue(params); + } + + @Override + public SuccessResultList> listPageAll(ListPage page) { + PageHelper.startPage(page.getPage(), page.getRows()); + List populationDTOs = populationDao.listAll(page.getParams()); + PageInfo pageInfo = new PageInfo<>(populationDTOs); + return new SuccessResultList<>(populationDTOs, pageInfo.getPageNum(), pageInfo.getTotal()); + } + } \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/population/population-mapper.xml b/src/main/resources/mybatis/mapper/population/population-mapper.xml index 5f3fee4..02a0096 100644 --- a/src/main/resources/mybatis/mapper/population/population-mapper.xml +++ b/src/main/resources/mybatis/mapper/population/population-mapper.xml @@ -114,8 +114,34 @@ DELETE FROM house_population WHERE - house_id = #{houseId} - AND out_house != 1 + house_id = #{houseId} AND out_house != 1 + + + + UPDATE + house_population + SET + out_house = '1', + gmt_modified = #{gmtModified}, + modifier = #{modifier} + WHERE + is_delete = 0 + + AND + population_id IN + + #{populationIds[${index}]} + + + + + + UPDATE + house_population + SET + bind_time = #{bindTime} + WHERE + population_id = #{populationId} @@ -224,6 +250,38 @@ + + + +