springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngPopulationServeExcelListen.java
New file @@ -0,0 +1,61 @@ package com.panzhihua.common.listen; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.exceptions.ServiceException; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComMngPopulationServeExcelVO; import com.panzhihua.common.model.vos.community.ComMngVillageServeExcelVO; import com.panzhihua.common.service.community.CommunityService; import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; import java.util.List; /** * @description: 实有人口导入监听 * @author: llming */ @Slf4j public class ComMngPopulationServeExcelListen extends AnalysisEventListener<ComMngPopulationServeExcelVO> { private CommunityService communityService; private Long communityId; public ComMngPopulationServeExcelListen(CommunityService communityService, Long communityId) { this.communityService = communityService; this.communityId = communityId; } private static final int BATCH_COUNT = 100; private List<ComMngPopulationServeExcelVO> list = new ArrayList<>(); @Override public void invoke(ComMngPopulationServeExcelVO comMngPopulationServeExcelVO, AnalysisContext analysisContext) { list.add(comMngPopulationServeExcelVO); // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM if (list.size() >= BATCH_COUNT) { log.info("excel导入数据【{}】", JSONObject.toJSONString(list)); R r = communityService.listSavePopulationServeExcelVO(list, this.communityId); if (!R.isOk(r)) { throw new ServiceException(r.getMsg()); } //清空list list.clear(); } } @Override public void doAfterAllAnalysed(AnalysisContext analysisContext) { log.info("excel导入数据【{}】", JSONObject.toJSONString(list)); //确保最后遗留的数据保存在数据库中 R r = this.communityService.listSavePopulationServeExcelVO(list, this.communityId); if (!R.isOk(r)) { throw new ServiceException(r.getMsg()); } } } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/community/ComMngPopulationServeExcelVO.java
New file @@ -0,0 +1,59 @@ package com.panzhihua.common.model.vos.community; import com.alibaba.excel.annotation.ExcelProperty; import lombok.Data; import java.io.Serializable; /** * @description: 批量导入实有人口 * @author: llming */ @Data public class ComMngPopulationServeExcelVO implements Serializable { @ExcelProperty(value = "家庭成员(姓名)" ,index = 0) private String name; @ExcelProperty(value = "性别(1.男 2.女 3.未知)" ,index = 1) private Integer sex; @ExcelProperty(value = "年龄" ,index = 2) private Integer age; @ExcelProperty(value = "是否租住" ,index = 3) private Integer adsf; @ExcelProperty(value = "街路巷" ,index = 4) private String road; @ExcelProperty(value = "门牌号" ,index = 5) private Integer doorNo; @ExcelProperty(value = "楼排号" ,index = 6) private String floor; @ExcelProperty(value = "单元号" ,index = 7) private Integer unitNo; @ExcelProperty(value = "户室(房间号)" ,index = 8) private Integer houseNo; @ExcelProperty(value = "民族" ,index = 9) private String nation; @ExcelProperty(value = "政治面貌(1.中共党员2.中共预备党员3.共青团员4.民革党员5.民盟盟员6.民建会员7.8.农工党党员9.致公党党员10.九三学社社员11.台盟盟员12.无党派人士13.群众)" ,index = 10) private Integer politicalOutlook; @ExcelProperty(value = "身份证号码" ,index = 11) private String cardNo; @ExcelProperty(value = "联系方式" ,index = 12) private String phone; @ExcelProperty(value = "籍贯" ,index = 13) private String nativePlace; @ExcelProperty(value = "工作单位" ,index = 14) private String workCompany; } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/community/CommunityService.java
@@ -1568,4 +1568,14 @@ */ @PostMapping("/village/import") R listSaveVillageServeExcelVO(@RequestBody List<ComMngVillageServeExcelVO> list, @RequestParam(value = "communityId") Long communityId); /** * 批量导入实有人口 * @param list * @param communityId * @return */ @PostMapping("/population/import") R listSavePopulationServeExcelVO(List<ComMngPopulationServeExcelVO> list,@RequestParam(value = "communityId") Long communityId); } springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/CommonDataApi.java
@@ -9,9 +9,7 @@ import com.alibaba.fastjson.JSONObject; import com.jcraft.jsch.SftpException; import com.panzhihua.common.controller.BaseController; import com.panzhihua.common.listen.ComMngCarExcelListen; import com.panzhihua.common.listen.ComMngRealAssetsExcelListen; import com.panzhihua.common.listen.ComMngRealCompanyExcelListen; import com.panzhihua.common.listen.*; import com.panzhihua.common.model.dtos.community.*; import com.panzhihua.common.model.dtos.user.*; import com.panzhihua.common.model.vos.LoginUserInfoVO; @@ -70,6 +68,7 @@ private String companyUrl = "http://panzhihua.nhys.cdnhxx.com/web/%e5%ae%9e%e6%9c%89%e5%8d%95%e4%bd%8d%e5%af%bc%e5%85%a5%e6%a8%a1%e6%9d%bf.xlsx"; @Value("${excel.assetsUrl}") private String assetsUrl = "http://panzhihua.nhys.cdnhxx.com/web/%e5%ae%9e%e6%9c%89%e5%8d%95%e4%bd%8d%e5%af%bc%e5%85%a5%e6%a8%a1%e6%9d%bf.xlsx"; private String excelPopulationUrl="http://panzhihua.nhys.cdnhxx.com/web/实有人口导入.xlsx"; // FTP 登录用户名 @Value("${ftp.username}") @@ -677,5 +676,30 @@ return communityService.pagePopulation(comMngPopulationVO); } @ApiOperation(value = "下载模板-实有人口") @GetMapping(value = "/serve/download/population/template") public R downloadPopulationTemplate(HttpServletResponse response) throws IOException, SftpException { return R.ok(excelPopulationUrl); } @ApiOperation(value = "excel导入实有人口") @PostMapping(value = "/serve/population/import", consumes = "multipart/*", headers = "content-type=multipart/form-date") public R downloadPopulationTemplate(@RequestParam MultipartFile file, HttpServletRequest request) { //获取文件名 String fileName = file.getOriginalFilename(); log.info("传入文件名字【{}】", fileName); InputStream inputStream = null; try { inputStream = file.getInputStream(); LoginUserInfoVO loginUserInfo = this.getLoginUserInfo(); ComMngPopulationServeExcelListen comMngPopulationServeExcelListen = new ComMngPopulationServeExcelListen(communityService, loginUserInfo.getCommunityId()); EasyExcel.read(inputStream, ComMngPopulationServeExcelVO.class, comMngPopulationServeExcelListen).sheet().doRead(); } catch (IOException e) { log.error("导入模板失败【{}】", e.getMessage()); e.printStackTrace(); } return R.ok(); } } springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/VillageApi.java
@@ -34,7 +34,6 @@ @RestController @RequestMapping("/villagemanager/") public class VillageApi extends BaseController { @Value("${excel.convenientUrl}") private String excelConvenientUrl = "http://panzhihua.nhys.cdnhxx.com/web/实有房屋导入模板.xlsx"; @Resource private CommunityService communityService; springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/api/ComMngVillageApi.java
@@ -73,7 +73,7 @@ /** * 社区后台导入实有房屋 * @param list 车辆列表 * @param list 数据 * @param communityId 社区编号 * @return */ springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/api/CommonDataApi.java
@@ -5,6 +5,7 @@ import com.panzhihua.common.model.vos.community.*; import com.panzhihua.service_community.service.*; import lombok.extern.slf4j.Slf4j; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -255,4 +256,16 @@ public R pagePopulation(@RequestBody ComMngPopulationDTO comMngPopulationVO) { return comMngPopulationService.pagePopulation(comMngPopulationVO); } /** * 社区后台导入实有人口 * @param list 数据 * @param communityId 社区编号 * @return */ @PostMapping("/population/import") @Transactional(rollbackFor = Exception.class) public R listSavePopulationExcelVO(@RequestBody List<ComMngPopulationServeExcelVO> list, @RequestParam(value = "communityId") Long communityId){ return comMngPopulationService.listSavePopulation(list,communityId); } } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComMngPopulationService.java
@@ -2,9 +2,12 @@ import com.panzhihua.common.model.dtos.community.ComMngPopulationDTO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComMngPopulationServeExcelVO; import com.panzhihua.common.model.vos.community.ComMngPopulationVO; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import java.util.List; /** * 实有人口Service @@ -51,4 +54,12 @@ * @return 删除结果 */ R deletePopulation(Long populationId); /** * 导入实有人口 * @param list * @param communityId * @return */ R listSavePopulation(List<ComMngPopulationServeExcelVO> list, Long communityId); } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationServiceImpl.java
@@ -4,12 +4,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.collect.Lists; import com.panzhihua.common.model.dtos.community.ComMngPopulationDTO; import com.panzhihua.common.model.dtos.community.PageComActDTO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComActActivityVO; import com.panzhihua.common.model.vos.community.ComActVO; import com.panzhihua.common.model.vos.community.ComMngPopulationVO; import com.panzhihua.common.model.vos.community.*; import com.panzhihua.common.model.vos.user.ComMngFamilyInfoVO; import com.panzhihua.service_community.dao.ComActActivityDAO; import com.panzhihua.service_community.dao.ComActDAO; @@ -17,6 +16,7 @@ import com.panzhihua.service_community.model.dos.ComActActivityDO; import com.panzhihua.service_community.model.dos.ComActDO; import com.panzhihua.service_community.model.dos.ComMngPopulationDO; import com.panzhihua.service_community.model.dos.ComMngVillageDO; import com.panzhihua.service_community.service.ComMngPopulationService; import org.springframework.beans.BeanUtils; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -39,27 +39,30 @@ /** * 新增实有人口 * * @param comMngPopulationVO 新增信息 * @return 新增结果 */ @Override public R addPopulation(ComMngPopulationVO comMngPopulationVO) { ComMngPopulationDO comMngPopulationDO=new ComMngPopulationDO(); ComMngPopulationDO comMngPopulationDO = new ComMngPopulationDO(); Integer integer = populationDAO.selectCount(new QueryWrapper<ComMngPopulationDO>().lambda().eq(ComMngPopulationDO::getCardNo, comMngPopulationVO.getCardNo())); if (integer>0) { if (integer > 0) { return R.fail("实有人口已经存在"); } BeanUtils.copyProperties(comMngPopulationVO,comMngPopulationDO); BeanUtils.copyProperties(comMngPopulationVO, comMngPopulationDO); int nub = populationDAO.insert(comMngPopulationDO); if(nub < 1){ if (nub < 1) { return R.fail(); } return R.ok(nub); } /** * 编辑实有人口 * * @param comMngPopulationVO 编辑内容 * @return 编辑结果 */ @@ -69,10 +72,10 @@ if (comMngPopulationDO == null) { return R.fail("未查询到人口记录"); } BeanUtils.copyProperties(comMngPopulationVO,comMngPopulationDO); BeanUtils.copyProperties(comMngPopulationVO, comMngPopulationDO); int nub = populationDAO.updateById(comMngPopulationDO); if(nub < 1){ if (nub < 1) { return R.fail(); } return R.ok(); @@ -103,11 +106,11 @@ return R.fail(); } ComMngPopulationVO comMngPopulationVO = new ComMngPopulationVO(); BeanUtils.copyProperties(comMngPopulationDO,comMngPopulationVO); BeanUtils.copyProperties(comMngPopulationDO, comMngPopulationVO); //查询家庭成员信息 List<ComMngFamilyInfoVO> comMngFamilyInfoVOS = populationDAO.listFamilyByUserId(comMngPopulationDO.getId()); if(!comMngFamilyInfoVOS.isEmpty()){ if (!comMngFamilyInfoVOS.isEmpty()) { comMngPopulationVO.setComMngFamilyInfoVOS(comMngFamilyInfoVOS); } return R.ok(comMngPopulationVO); @@ -124,10 +127,10 @@ Page page = new Page<>(); Long pageNum = comMngPopulationVO.getPageNum(); Long pageSize = comMngPopulationVO.getPageSize(); if (null==pageNum||0==pageNum) { if (null == pageNum || 0 == pageNum) { pageNum = 1l; } if (null==pageSize||0==pageSize) { if (null == pageSize || 0 == pageSize) { pageSize = 10l; } page.setSize(pageSize); @@ -145,7 +148,7 @@ @Override public R deletePopulation(Long populationId) { int delete = populationDAO.deleteById(populationId); if (delete>0) { if (delete > 0) { return R.ok(); } return R.fail(); @@ -159,14 +162,77 @@ @Override public R listPopulationAll() { List<ComMngPopulationDO> populationDOS = populationDAO.selectList(new QueryWrapper<ComMngPopulationDO>().lambda().orderByDesc(ComMngPopulationDO::getCreateAt)); List<ComMngPopulationVO> populationVOS=new ArrayList<>(); List<ComMngPopulationVO> populationVOS = new ArrayList<>(); if (!ObjectUtils.isEmpty(populationDOS)) { populationDOS.forEach(comActDO -> { ComMngPopulationVO populationVO=new ComMngPopulationVO(); BeanUtils.copyProperties(comActDO,populationVO); ComMngPopulationVO populationVO = new ComMngPopulationVO(); BeanUtils.copyProperties(comActDO, populationVO); populationVOS.add(populationVO); }); } return R.ok(populationVOS); } @Override public R listSavePopulation(List<ComMngPopulationServeExcelVO> list, Long communityId) { /* //思路:实有房屋(小区)当前是存在重复人口,打印已经存在的重复数据 List<ComMngPopulationDO> comMngPopulationDOS = populationDAO.selectList(new QueryWrapper<ComMngPopulationDO>().lambda().eq(ComMngPopulationDO::getActId, communityId)); if (list.size() == 0) { return R.fail("数据为空!"); } judgeEmpty(list); ComActDO comActDO = comActDAO.selectById(communityId); ArrayList<ComMngVillageDO> comMngVillageDOS = Lists.newArrayList(); list.forEach(vo -> { ComMngVillageDO comMngVillageDO = new ComMngVillageDO(); BeanUtils.copyProperties(vo, comMngVillageDO); comMngVillageDO.setCommunityId(comActDO.getCommunityId()); comMngVillageDO.setStreetId(comActDO.getStreetId()); comMngVillageDOS.add(comMngVillageDO); }); this.saveBatch(comMngVillageDOS); return R.ok("共计导入实有房屋数量:" + comMngVillageDOS.size());*/ return null; } /** * excel数据校验 * * @param list */ private void judgeEmpty(List<ComMngPopulationServeExcelVO> list) { /*int index = 2; for (ComMngPopulationServeExcelVO vo : list) { ComMngPopulationServeExcelVO comMngPopulationServeExcelVO = new ComMngPopulationServeExcelVO(); comMngPopulationServeExcelVO.setName(""); comMngPopulationServeExcelVO.setSex(0); comMngPopulationServeExcelVO.setAge(0); comMngPopulationServeExcelVO.setAdsf(0); comMngPopulationServeExcelVO.setRoad(""); comMngPopulationServeExcelVO.setDoorNo(0); comMngPopulationServeExcelVO.setFloor(""); comMngPopulationServeExcelVO.setUnitNo(0); comMngPopulationServeExcelVO.setHouseNo(0); comMngPopulationServeExcelVO.setNation(""); comMngPopulationServeExcelVO.setPoliticalOutlook(0); comMngPopulationServeExcelVO.setCardNo(""); comMngPopulationServeExcelVO.setPhone(""); comMngPopulationServeExcelVO.setNativePlace(""); comMngPopulationServeExcelVO.setWorkCompany(""); if (vo.get() == null) { return R.fail("门牌号第" + index + "行为空!"); } if (vo.getAlley() == null) { return R.fail("街路巷第" + index + "行为空!"); } //判断DB和exel数据重复判断 boolean result = comMngVillageDOs.stream().allMatch(village -> village.getAlley().equals(vo.getAlley()) && village.getHouseNum().equals(vo.getHouseNum())); if (result) { return R.fail("导入街路巷已存在(" + vo.getAlley() + ")"); } index++; }*/ } } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngVillageServiceImpl.java
@@ -109,10 +109,10 @@ @Override public R listSaveVillage(List<ComMngVillageServeExcelVO> list, Long communityId) { //思路:获取社区下所有的实有房屋(小区),打印已经存在的重复数据 List<ComMngVillageDO> comMngVillageDOs = comActVillageDAO.selectList(new QueryWrapper<ComMngVillageDO>().lambda().eq(ComMngVillageDO::getCommunityId, communityId)); if (list.size() == 0) { return R.fail("数据为空!"); } List<ComMngVillageDO> comMngVillageDOs = comActVillageDAO.selectList(new QueryWrapper<ComMngVillageDO>().lambda().eq(ComMngVillageDO::getCommunityId, communityId)); int index = 2; for (ComMngVillageServeExcelVO vo : list) { if (vo.getHouseNum() == null) {