diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/RegisterAndBindFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/RegisterAndBindFormDTO.java new file mode 100644 index 0000000000..5869490ead --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/RegisterAndBindFormDTO.java @@ -0,0 +1,70 @@ +package com.epmet.dto.form; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @Description + * @Author zhaoqifeng + * @Date 2022/6/1 9:39 + */ +@NoArgsConstructor +@Data +public class RegisterAndBindFormDTO implements Serializable { + + private static final long serialVersionUID = 7068763631425911170L; + private String customerId; + private String userId; + /** + * 姓 + */ + private String surname; + /** + * 名 + */ + private String name; + /** + * 昵称 + */ + private String nickname; + /** + * 头像 + */ + private String headImgUrl; + /** + * 身份证 + */ + private String idCard; + /** + * 手机号 + */ + private String mobile; + /** + * 网格 + */ + private String gridId; + /** + * 小区 + */ + private String villageId; + /** + * 楼栋 + */ + private String buildId; + /** + * 单元 + */ + private String unitId; + /** + * 房屋 + */ + private String homeId; + /** + * 路牌号 + */ + private String address; + + private String visitId; +} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/HomeInfoResultDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/HomeInfoResultDTO.java new file mode 100644 index 0000000000..5ff591455f --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/HomeInfoResultDTO.java @@ -0,0 +1,22 @@ +package com.epmet.dto.result; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @Description + * @Author zhaoqifeng + * @Date 2022/6/1 16:49 + */ +@NoArgsConstructor +@Data +public class HomeInfoResultDTO implements Serializable { + + private static final long serialVersionUID = -6109420020924607393L; + private String icResiUserId; + private String houseName; + private String houseCode; + private String qrCodeUrl; +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/MyHomeController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/MyHomeController.java index 64da6e6e16..87ef1f64d8 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/MyHomeController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/MyHomeController.java @@ -1,16 +1,8 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; -import com.epmet.commons.tools.security.dto.TokenDto; -import com.epmet.commons.tools.utils.Result; -import com.epmet.dto.result.HomeUserBriefResultDTO; -import com.epmet.service.MyHomeService; -import lombok.extern.slf4j.Slf4j; -import oracle.jdbc.proxy.annotation.Post; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; import com.epmet.commons.tools.enums.HomeMemberOperationEnum; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.group.AddGroup; @@ -18,13 +10,14 @@ import com.epmet.commons.tools.validator.group.DefaultGroup; import com.epmet.dto.IcResiUserConfirmDTO; import com.epmet.dto.form.IcResiUserConfirmGetDTO; import com.epmet.dto.form.IcResiUserConfirmSubmitDTO; +import com.epmet.dto.form.RegisterAndBindFormDTO; +import com.epmet.dto.result.HomeInfoResultDTO; +import com.epmet.dto.result.HomeUserBriefResultDTO; import com.epmet.service.IcResiUserConfirmService; +import com.epmet.service.MyHomeService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -110,4 +103,26 @@ public class MyHomeController { return icResiUserConfirmService.getMemberDetail(dto); } + /** + * 注册绑定家庭信息 + * + * @Param tokenDto + * @Param formDTO + * @Return {@link Result} + * @Author zhaoqifeng + * @Date 2022/6/1 10:26 + */ + @PostMapping("registerAndBind") + public Result registerAndBind(@LoginUser TokenDto tokenDto, RegisterAndBindFormDTO formDTO) { + formDTO.setCustomerId(tokenDto.getCustomerId()); + formDTO.setUserId(tokenDto.getUserId()); + myHomeService.registerAndBind(formDTO); + return new Result(); + } + + @PostMapping("homeInfo") + public Result getHomeInfo(@LoginUser TokenDto tokenDto) { + HomeInfoResultDTO result = myHomeService.getHomeInfo(tokenDto); + return new Result().ok(result); + } } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/MyHomeService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/MyHomeService.java index 1eae402d2f..0d1667b03d 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/MyHomeService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/MyHomeService.java @@ -1,8 +1,9 @@ package com.epmet.service; +import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.dto.form.RegisterAndBindFormDTO; +import com.epmet.dto.result.HomeInfoResultDTO; import com.epmet.dto.result.HomeUserBriefResultDTO; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; import java.util.List; @@ -12,6 +13,25 @@ import java.util.List; * @Date 2022/5/31 16:21 */ public interface MyHomeService { + /** + * 注册绑定房屋信息 + * + * @Param formDTO + * @Return + * @Author zhaoqifeng + * @Date 2022/6/1 16:33 + */ + void registerAndBind(RegisterAndBindFormDTO formDTO); + + /** + * 获取用户绑定的房屋信息 + * + * @Param tokenDto + * @Return {@link HomeInfoResultDTO} + * @Author zhaoqifeng + * @Date 2022/6/1 16:52 + */ + HomeInfoResultDTO getHomeInfo(TokenDto tokenDto); /** * 查询家庭成员 diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/MyHomeServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/MyHomeServiceImpl.java index 6bf9364dd9..741e3fd82b 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/MyHomeServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/MyHomeServiceImpl.java @@ -1,17 +1,41 @@ package com.epmet.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.redis.common.CustomerIcHouseRedis; +import com.epmet.commons.tools.redis.common.CustomerOrgRedis; +import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; +import com.epmet.commons.tools.redis.common.bean.HouseInfoCache; +import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; +import com.epmet.dao.IcResiUserDao; +import com.epmet.dao.UserBaseInfoDao; +import com.epmet.dao.UserResiInfoDao; +import com.epmet.dao.UserRoleDao; import com.epmet.dto.IcHouseDTO; +import com.epmet.dto.UserResiInfoDTO; +import com.epmet.dto.form.GetRoleKeyListFormDTO; +import com.epmet.dto.form.RegisterAndBindFormDTO; +import com.epmet.dto.result.HomeInfoResultDTO; import com.epmet.dto.result.HomeUserBriefResultDTO; -import com.epmet.feign.GovOrgFeignClient; +import com.epmet.dto.result.ResiUserBaseInfoResultDTO; +import com.epmet.entity.IcResiUserEntity; +import com.epmet.entity.UserBaseInfoEntity; +import com.epmet.entity.UserResiInfoEntity; import com.epmet.feign.GovOrgOpenFeignClient; import com.epmet.service.IcResiUserService; import com.epmet.service.MyHomeService; +import com.epmet.service.UserBaseInfoService; +import com.epmet.service.UserResiInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.compress.utils.Lists; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import java.util.List; /** @@ -25,9 +49,20 @@ public class MyHomeServiceImpl implements MyHomeService { @Autowired private GovOrgOpenFeignClient govOrgOpenFeignClient; - @Autowired private IcResiUserService icResiUserService; + @Resource + private UserRoleDao userRoleDao; + @Resource + private UserResiInfoService userResiInfoService; + @Resource + private UserResiInfoDao userResiInfoDao; + @Resource + private UserBaseInfoService userBaseInfoService; + @Resource + private UserBaseInfoDao userBaseInfoDao; + @Resource + private IcResiUserDao icResiUserDao; @Override public List selectListHomeMember(String houseCode, String customerId) { @@ -40,4 +75,112 @@ public class MyHomeServiceImpl implements MyHomeService { return Lists.newArrayList(); } + + /** + * 注册绑定房屋信息 + * + * @Param formDTO + * @Return + * @Author zhaoqifeng + * @Date 2022/6/1 16:33 + */ + @Override + public void registerAndBind(RegisterAndBindFormDTO formDTO) { + //TODO 是否走进入网格(entergrid)流程 + //1.判断是否是居民,如果不是则注册居民,如果是则更新居民信息 + GetRoleKeyListFormDTO getRoleKeyListFormDTO = new GetRoleKeyListFormDTO(); + getRoleKeyListFormDTO.setUserId(formDTO.getUserId()); + getRoleKeyListFormDTO.setGridId(formDTO.getGridId()); + List roleList = userRoleDao.selectUserRoleKeyList(getRoleKeyListFormDTO); + + if (CollectionUtils.isNotEmpty(roleList) && roleList.contains("registered_resi")) { + //更新user_resi_info和user_base_info的信息 + UserResiInfoEntity userResiInfo = new UserResiInfoEntity(); + userResiInfo.setSurname(formDTO.getSurname()); + userResiInfo.setName(formDTO.getName()); + userResiInfo.setIdNum(formDTO.getIdCard()); + userResiInfo.setRegMobile(formDTO.getMobile()); + userResiInfo.setResiVisitId(formDTO.getVisitId()); + userResiInfo.setDistrict(formDTO.getAddress()); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(UserResiInfoEntity::getCustomerId, formDTO.getCustomerId()); + wrapper.eq(UserResiInfoEntity::getUserId, formDTO.getUserId()); + userResiInfoDao.update(userResiInfo, wrapper); + + UserBaseInfoEntity userBaseInfoEntity = ConvertUtils.sourceToTarget(userResiInfo, UserBaseInfoEntity.class); + userBaseInfoService.insertOrUpdate(userBaseInfoEntity); + } else { + //注册居民 + UserResiInfoDTO userResiInfoDTO = ConvertUtils.sourceToTarget(formDTO, UserResiInfoDTO.class); + userResiInfoDTO.setIdNum(formDTO.getIdCard()); + userResiInfoDTO.setRegMobile(formDTO.getMobile()); + userResiInfoDTO.setResiVisitId(formDTO.getVisitId()); + userResiInfoDTO.setDistrict(formDTO.getAddress()); + userResiInfoDTO.setCustomerId(formDTO.getCustomerId()); + userResiInfoDTO.setApp("resi"); + userResiInfoService.saveResiInfo(userResiInfoDTO); + } + //2.添加ic_resi_user信息 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(IcResiUserEntity::getCustomerId, formDTO.getCustomerId()); + wrapper.eq(IcResiUserEntity::getIdCard, formDTO.getIdCard()); + IcResiUserEntity icUser = icResiUserDao.selectOne(wrapper); + + HouseInfoCache houseInfo = CustomerIcHouseRedis.getHouseInfo(formDTO.getCustomerId(), formDTO.getHomeId()); + if (null == houseInfo) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取房屋信息失败", "获取房屋信息失败"); + } + AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(houseInfo.getAgencyId()); + if (null == agencyInfo) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取组织信息失败", "获取组织信息失败"); + } + IcResiUserEntity icUserEntity = ConvertUtils.sourceToTarget(formDTO, IcResiUserEntity.class); + icUserEntity.setName(formDTO.getSurname() + formDTO.getName()); + icUserEntity.setAgencyId(houseInfo.getAgencyId()); + icUserEntity.setPids(agencyInfo.getPids()); + if (null != icUser) { + icUserEntity.setId(icUser.getId()); + icResiUserDao.updateById(icUserEntity); + } else { + icResiUserDao.insert(icUserEntity); + } + } + + /** + * 获取用户绑定的房屋信息 + * + * @param tokenDto + * @Param tokenDto + * @Return {@link HomeInfoResultDTO} + * @Author zhaoqifeng + * @Date 2022/6/1 16:52 + */ + @Override + public HomeInfoResultDTO getHomeInfo(TokenDto tokenDto) { + HomeInfoResultDTO resultDto = new HomeInfoResultDTO(); + ResiUserBaseInfoResultDTO baseInfo = userBaseInfoDao.selecUserBaseInfoByUserId(tokenDto.getUserId()); + if (null == baseInfo) { + return resultDto; + } + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(IcResiUserEntity::getCustomerId, tokenDto.getCustomerId()); + wrapper.eq(IcResiUserEntity::getIdCard, baseInfo.getIdNum()); + IcResiUserEntity icUser = icResiUserDao.selectOne(wrapper); + + if (null == icUser) { + return resultDto; + } + resultDto.setIcResiUserId(icUser.getId()); + //TODO 获取房屋信息 + HouseInfoCache houseInfo = CustomerIcHouseRedis.getHouseInfo(tokenDto.getCustomerId(), icUser.getHomeId()); + if (null == houseInfo) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取房屋信息失败", "获取房屋信息失败"); + } + resultDto.setHouseName(houseInfo.getAllName()); + resultDto.setHouseCode(null); + resultDto.setQrCodeUrl(null); + return resultDto; + } }