diff --git a/src/main/java/com/cm/population/controller/apis/buildinghouse/BuildingHouseController.java b/src/main/java/com/cm/population/controller/apis/buildinghouse/BuildingHouseController.java index d6307c5..5924950 100644 --- a/src/main/java/com/cm/population/controller/apis/buildinghouse/BuildingHouseController.java +++ b/src/main/java/com/cm/population/controller/apis/buildinghouse/BuildingHouseController.java @@ -165,7 +165,9 @@ public class BuildingHouseController extends AbstractController { String fileName = URLEncoder.encode(excelName, "UTF-8"); response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); - String [] headers = {"序号", "小区名称(必填)", "楼宇名称", "房屋编号(必填)", "房屋状态(必填)", "房主姓名(必填)", "房主身份证号(必填)", "房主联系方式(必填)", "住户身份证号(多个用逗号隔开)"}; + String [] headers = {"序号", "小区名称(必填)", "楼宇名称", "房屋编号(必填)", + "房屋状态(必填)", "房主姓名(必填)", "房主身份证号(必填)", + "房主联系方式(必填)", "住户姓名(必填)", "身份证号(必填)", "联系方式(必填)", "与户主关系"}; List> listHeader = new ArrayList<>(); for(String item : headers) { List title = new ArrayList<>(); @@ -188,7 +190,10 @@ public class BuildingHouseController extends AbstractController { data.add(buildingHouseModel.getOwnerName()); data.add(buildingHouseModel.getOwnerCard()); data.add(buildingHouseModel.getOwnerPhone()); - data.add(buildingHouseModel.getCardNumbers()); + data.add(buildingHouseModel.getHouseholdName()); + data.add(buildingHouseModel.getHouseholdCard()); + data.add(buildingHouseModel.getHouseholdPhone()); + data.add(buildingHouseModel.getRelationship()); data.add(dto.getErrMsg()); listData.add(data); } diff --git a/src/main/java/com/cm/population/controller/apis/buildinghouseuser/BuildingHouseUserController.java b/src/main/java/com/cm/population/controller/apis/buildinghouseuser/BuildingHouseUserController.java index 6947b22..9870537 100644 --- a/src/main/java/com/cm/population/controller/apis/buildinghouseuser/BuildingHouseUserController.java +++ b/src/main/java/com/cm/population/controller/apis/buildinghouseuser/BuildingHouseUserController.java @@ -1,33 +1,23 @@ package com.cm.population.controller.apis.buildinghouseuser; -import com.alibaba.fastjson.JSONObject; import com.cm.common.annotation.CheckRequestBodyAnnotation; import com.cm.common.base.AbstractController; import com.cm.common.constants.ISystemConstant; -import com.cm.common.plugin.oauth.token.ClientTokenManager; -import com.cm.common.plugin.pojo.bos.ClientTokenBO; import com.cm.common.pojo.ListPage; import com.cm.common.result.ErrorResult; import com.cm.common.result.SuccessResult; import com.cm.common.result.SuccessResultData; import com.cm.common.result.SuccessResultList; -import com.cm.population.config.properties.ProjectProperties; import com.cm.population.pojo.dtos.buildinghouseuser.BuildingHouseUserDTO; import com.cm.population.pojo.vos.buildinghouseuser.BuildingHouseUserVO; import com.cm.population.service.buildinghouseuser.IBuildingHouseUserService; import com.cm.population.service.personmsg.IPersonMsgService; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; import javax.mail.search.SearchException; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/src/main/java/com/cm/population/pojo/model/buildinghouse/BuildingHouseModel.java b/src/main/java/com/cm/population/pojo/model/buildinghouse/BuildingHouseModel.java index ec5f5e6..4d9f6d8 100644 --- a/src/main/java/com/cm/population/pojo/model/buildinghouse/BuildingHouseModel.java +++ b/src/main/java/com/cm/population/pojo/model/buildinghouse/BuildingHouseModel.java @@ -26,7 +26,13 @@ public class BuildingHouseModel { @ExcelProperty(index = 7) private String ownerPhone; @ExcelProperty(index = 8) - private String cardNumbers; + private String householdName; + @ExcelProperty(index = 9) + private String householdCard; + @ExcelProperty(index = 10) + private String householdPhone; + @ExcelProperty(index = 11) + private String relationship; private String districtId; private String cityBuildingId; @@ -95,12 +101,36 @@ public class BuildingHouseModel { this.ownerPhone = ownerPhone; } - public String getCardNumbers() { - return cardNumbers; + public String getHouseholdName() { + return householdName; } - public void setCardNumbers(String cardNumbers) { - this.cardNumbers = cardNumbers; + public void setHouseholdName(String householdName) { + this.householdName = householdName; + } + + public String getHouseholdCard() { + return householdCard; + } + + public void setHouseholdCard(String householdCard) { + this.householdCard = householdCard; + } + + public String getHouseholdPhone() { + return householdPhone; + } + + public void setHouseholdPhone(String householdPhone) { + this.householdPhone = householdPhone; + } + + public String getRelationship() { + return relationship; + } + + public void setRelationship(String relationship) { + this.relationship = relationship; } public String getDistrictId() { diff --git a/src/main/java/com/cm/population/service/buildinghouseuser/impl/BuildingHouseUserServiceImpl.java b/src/main/java/com/cm/population/service/buildinghouseuser/impl/BuildingHouseUserServiceImpl.java index 3d5b058..02be78f 100644 --- a/src/main/java/com/cm/population/service/buildinghouseuser/impl/BuildingHouseUserServiceImpl.java +++ b/src/main/java/com/cm/population/service/buildinghouseuser/impl/BuildingHouseUserServiceImpl.java @@ -2,7 +2,10 @@ package com.cm.population.service.buildinghouseuser.impl; import com.cm.common.base.AbstractService; import com.cm.common.pojo.ListPage; +import com.cm.common.pojo.bos.UserInfoBO; import com.cm.common.result.SuccessResultList; +import com.cm.common.token.app.AppTokenManager; +import com.cm.common.token.app.entity.AppTokenUser; import com.cm.common.utils.HashMapUtil; import com.cm.common.utils.UUIDUtil; import com.cm.population.dao.buildinghouseuser.IBuildingHouseUserDao; diff --git a/src/main/java/com/cm/population/service/handleimportexcelhouse/impl/HandleImportExcelHouseServiceImpl.java b/src/main/java/com/cm/population/service/handleimportexcelhouse/impl/HandleImportExcelHouseServiceImpl.java index 3e5df1c..580cd22 100644 --- a/src/main/java/com/cm/population/service/handleimportexcelhouse/impl/HandleImportExcelHouseServiceImpl.java +++ b/src/main/java/com/cm/population/service/handleimportexcelhouse/impl/HandleImportExcelHouseServiceImpl.java @@ -3,6 +3,7 @@ package com.cm.population.service.handleimportexcelhouse.impl; import com.alibaba.excel.util.StringUtils; import com.alibaba.fastjson.JSONObject; import com.cm.common.base.AbstractService; +import com.cm.common.exception.SaveException; import com.cm.common.plugin.oauth.token.ClientTokenManager; import com.cm.common.plugin.pojo.bos.ClientTokenBO; import com.cm.common.result.SuccessResultData; @@ -77,17 +78,6 @@ public class HandleImportExcelHouseServiceImpl extends AbstractService implement BuildingHouseDTO buildinghouseDTO = buildingHouseDao.get(params); params = new HashMap<>(); if(null != buildinghouseDTO) { - /*params.put("cityBuildingId",buildingHouseModel.getCityBuildingId()); - params.put("cityBuildingName",buildingHouseModel.getCityBuildingName()); - params.put("houseNumber",buildingHouseModel.getHouseNumber()); - params.put("districtName",buildingHouseModel.getDistrictName()); - params.put("districtId",buildingHouseModel.getDistrictId()); - params.put("houseStatus",buildingHouseModel.getHouseStatus()); - params.put("dataType",3); - params.put("ownerName",buildingHouseModel.getOwnerName()); - params.put("ownerCard",buildingHouseModel.getOwnerCard()); - params.put("ownerPhone",buildingHouseModel.getOwnerPhone()); - buildingHouseDao.update(params);*/ saveHouseUser(buildingHouseModel, buildinghouseDTO.getBuildingHouseId()); }else { BuildingHouseVO buildingHouseVO = new BuildingHouseVO(); @@ -109,6 +99,74 @@ public class HandleImportExcelHouseServiceImpl extends AbstractService implement } private void saveHouseUser(BuildingHouseModel buildingHouseModel, String buildingHouseId) throws Exception { + String ownerCard = buildingHouseModel.getOwnerCard(); + String householdCard = buildingHouseModel.getHouseholdCard(); + if(!StringUtils.isEmpty(ownerCard)) { + // 将所有的非英文半角逗号都转为英文半角 + ownerCard = ownerCard.replaceAll("\\n", ","); + ownerCard = ownerCard.replaceAll("\\r", ","); + ownerCard = ownerCard.replaceAll(" ", ","); + ownerCard = ownerCard.replaceAll(",", ","); + + ownerCard = ownerCard.replaceAll("[\\s]*[,][\\s]*[,]{1,}([\\s]+|[,]+)*", ","); + + buildingHouseModel.setOwnerCard(ownerCard); + } + if(!StringUtils.isEmpty(householdCard)) { + // 将所有的非英文半角逗号都转为英文半角 + householdCard = householdCard.replaceAll("\\n", ","); + householdCard = householdCard.replaceAll("\\r", ","); + householdCard = householdCard.replaceAll(" ", ","); + householdCard = householdCard.replaceAll(",", ","); + + householdCard = householdCard.replaceAll("[\\s]*[,][\\s]*[,]{1,}([\\s]+|[,]+)*", ","); + + buildingHouseModel.setHouseholdCard(householdCard); + } + + Map params = new HashMap<>(); + params.put("cardNumber", householdCard); + params.put("buildingHouseId", buildingHouseId); + SuccessResultData> data = userMsg(householdCard); + Map userParam = data.getData(); + if(null == userParam || userParam.isEmpty()) { + throw new SaveException("当前人员不存在于系统中"); + } + BuildingHouseUserVO buildingHouseUserVO = new BuildingHouseUserVO(); + buildingHouseUserVO.setBuildingHouseId(buildingHouseId); + buildingHouseUserVO.setCardNumber(householdCard); + buildingHouseUserVO.setName(userParam.get("name") == null ? buildingHouseModel.getHouseholdName() : userParam.get("name").toString()); + buildingHouseUserVO.setSex(userParam.get("sex") == null ? "" : userParam.get("sex").toString()); + buildingHouseUserVO.setPhone(userParam.get("phone") == null ? buildingHouseModel.getHouseholdPhone() : userParam.get("phone").toString()); + buildingHouseUserVO.setRelationship(buildingHouseModel.getRelationship()); + List buildingHouseUserDTOList = buildingHouseUserService.list(params); + BuildingHouseUserDTO updateDto = null; + Boolean userDo = false; + if(null != buildingHouseUserDTOList && buildingHouseUserDTOList.size() > 0) { + for(BuildingHouseUserDTO buildingHouseUserDTO: buildingHouseUserDTOList) { + if(buildingHouseUserDTO.getCardNumber().equals(householdCard) || buildingHouseUserDTO.getName().equals(userParam.get("name"))) { + userDo = true; + updateDto = buildingHouseUserDTO; + } + } + } + if(userDo) { + buildingHouseUserService.update(updateDto.getBuildingHouseUserId(), buildingHouseUserVO); + }else { + buildingHouseUserService.save(buildingHouseUserVO); + } + + /*String ownerName = buildingHouseModel.getOwnerName(); + if(!StringUtils.isEmpty(ownerName)) { + saveUserMsg(buildingHouseId, buildingHouseModel); + }else { + if(!StringUtils.isEmpty(ownerCard)) { + saveUserMsg(buildingHouseId, buildingHouseModel); + } + }*/ + } + + /*private void saveHouseUser(BuildingHouseModel buildingHouseModel, String buildingHouseId) throws Exception { String userIds = buildingHouseModel.getCardNumbers(); if(!StringUtils.isEmpty(userIds)) { Map params = new HashMap<>(); @@ -163,7 +221,7 @@ public class HandleImportExcelHouseServiceImpl extends AbstractService implement saveUserMsg(buildingHouseId, buildingHouseModel); } } - } + }*/ private void saveUserMsg(String buildingHouseId, BuildingHouseModel buildingHouseModel) throws Exception { String ownerName = buildingHouseModel.getOwnerName(); @@ -176,10 +234,11 @@ public class HandleImportExcelHouseServiceImpl extends AbstractService implement buildingHouseUserVO.setName(ownerName); buildingHouseUserVO.setCardNumber(ownerCard); buildingHouseUserVO.setPhone(buildingHouseModel.getOwnerPhone()); + buildingHouseUserVO.setRelationship(buildingHouseModel.getRelationship()); List buildingHouseUserDTOList = buildingHouseUserService.list(params); BuildingHouseUserDTO updateDto = null; Boolean userDo = false; - if(null == buildingHouseUserDTOList) { + if(null != buildingHouseUserDTOList && buildingHouseUserDTOList.size() > 0) { for(BuildingHouseUserDTO buildingHouseUserDTO: buildingHouseUserDTOList) { if(buildingHouseUserDTO.getCardNumber().equals(ownerCard) || buildingHouseUserDTO.getName().equals(ownerName)) { userDo = true; @@ -198,23 +257,6 @@ public class HandleImportExcelHouseServiceImpl extends AbstractService implement Map params = new HashMap<>(); params.put("idCardNumber", idCard); return new SuccessResultData<>(personMsgService.userMsg(params)); - /*ClientTokenBO token = ClientTokenManager.getInstance().getClientToken(); - RestTemplate restTemplate = new RestTemplate(); - String url = projectProperties.getPopulationUrl(); - url += "/resource/personMsg/userMsg/" + idCard; - UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) - .queryParam("access_token", token.getAccessToken()); - ResponseEntity responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, null, String.class); - String str = responseEntity.getBody(); - if(org.springframework.util.StringUtils.isEmpty(str)) { - return new SuccessResultData<>(new HashMap<>()); - } - JSONObject jsonObject = null; - jsonObject = JSONObject.parseObject(str).getJSONObject("data"); - if(null == jsonObject || jsonObject.size() <= 0) { - return new SuccessResultData<>(new HashMap<>()); - } - return new SuccessResultData<>(jsonObject);*/ } } diff --git a/src/main/resources/mybatis/mapper/buildinghouse/building-house-mapper.xml b/src/main/resources/mybatis/mapper/buildinghouse/building-house-mapper.xml index 7afe460..9879fc9 100644 --- a/src/main/resources/mybatis/mapper/buildinghouse/building-house-mapper.xml +++ b/src/main/resources/mybatis/mapper/buildinghouse/building-house-mapper.xml @@ -248,6 +248,9 @@ AND t1.city_building_id = #{cityBuildingId} + + AND t1.gmt_create = #{userId} + AND LEFT(t1.gmt_create, 10) = ]]> #{startTime} @@ -263,6 +266,7 @@ #{buildingHouseIds[${index}]} + ORDER BY t1.id desc