huanghongfa
2021-08-05 31eb44e38f79f3011ce19eb5bc657a08ab22cc3b
springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
@@ -17,17 +17,18 @@
import com.panzhihua.common.model.vos.community.ComActVO;
import com.panzhihua.common.model.vos.community.ComMngVolunteerMngVO;
import com.panzhihua.common.model.vos.grid.EventGridMemberRelationVO;
import com.panzhihua.common.model.vos.grid.GridMemberVO;
import com.panzhihua.common.model.vos.grid.admin.GridMemberBuildingVO;
import com.panzhihua.common.model.vos.partybuilding.ActivityManagerVO;
import com.panzhihua.common.model.vos.shop.ShopStoreVO;
import com.panzhihua.common.model.vos.user.*;
//import com.panzhihua.common.service.grid.GridService;
import com.panzhihua.common.service.partybuilding.PartyBuildingService;
import com.panzhihua.common.utlis.IdCard;
import com.panzhihua.common.utlis.RealNameUtil;
import com.panzhihua.common.utlis.SensitiveUtil;
import com.panzhihua.common.utlis.*;
import com.panzhihua.service_user.dao.*;
import com.panzhihua.service_user.model.dos.*;
import com.panzhihua.service_user.model.dtos.DataKanbanDTO;
import com.panzhihua.service_user.service.EventGridMemberBuildingRelationService;
import com.panzhihua.service_user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateFormatUtils;
@@ -81,6 +82,12 @@
    private SysMenuDAO sysMenuDAO;
    @Resource
    private SysUserInputDAO sysUserInputDAO;
    @Resource
    private EventGridMemberBuildingRelationService buildingRelationService;
    @Resource
    private EventGridMemberBuildingRelationMapper eventGridMemberBuildingRelationMapper;
    @Resource
    private LcCompareMemberCodeMapper lcCompareMemberCodeMapper;
//    @Resource
//    private GridService gridService;
@@ -165,7 +172,7 @@
        userDao.updateServiceTeam(purePhoneNumber, purePhoneNumber);
        int i = userDao.updateById(sysUserDO);
        if (i > 0) {
            return R.ok();
            return R.ok(purePhoneNumber);
        } else {
            return R.fail("维护微信手机号失败");
        }
@@ -619,23 +626,24 @@
        String idCard = loginUserInfoVO.getIdCard();
        String name = loginUserInfoVO.getName();
        log.info("用户实名认证发送请求,姓名:" + name + "身份证号码:" + idCard);
        try {
            boolean b = RealNameUtil.authentication(idCard, name);
            if (!b) {
                return R.fail("身份认证失败:请填写真实信息");
            }
        }catch (ServiceException serviceException){
            return R.fail(serviceException.getMessage());
        }
//        try {
//            boolean b = RealNameUtil.authentication(idCard, name);
//            if (!b) {
//                return R.fail("身份认证失败:请填写真实信息");
//            }
//        }catch (ServiceException serviceException){
//            return R.fail(serviceException.getMessage());
//        }
        SysUserDO sysUserDO = new SysUserDO();
        sysUserDO.setName(name);
        sysUserDO.setIdCard(idCard);
        //通过身份证号判断性别以及出生日期
        sysUserDO.setSex(IdCard.sex(idCard));
        sysUserDO.setBirthday(IdCard.birthDay(idCard));
        sysUserDO.setJob(loginUserInfoVO.getJob());
//        sysUserDO.setJob(loginUserInfoVO.getJob());
        sysUserDO.setUserId(loginUserInfoVO.getUserId());
        sysUserDO.setFaceUrl(loginUserInfoVO.getFaceUrl());
        sysUserDO.setPhone(loginUserInfoVO.getPhone());
        sysUserDO.setFaceState(null);
        SysUserDO sysUserDO1 = userDao.selectOne(new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getIdCard, idCard));
        if (!ObjectUtils.isEmpty(sysUserDO1)) {
@@ -653,6 +661,19 @@
                userDao.updateById(sysUserDO);
                //修改审核绑定的userId
                userDao.updateComPbMemberUserId(idCard,sysUserDO.getUserId());
            }
            SysUserDO user = userDao.selectById(loginUserInfoVO.getUserId());
            if(user != null){
                //实名认证成功推送订阅消息给用户
                try {
                    WxXCXTempSend util = new WxXCXTempSend();
                    String accessToken = util.getAppAccessToken();
                    //用户实名认证推送消息
                    WxUtil.sendSubscribeRZSH(user.getOpenid(),accessToken,"用户实名认证", com.panzhihua.common.utlis.DateUtils.getCurrentDateStr(),"审核通过");
                }catch (Exception e){
                    log.error("推送用户订阅消息失败,失败原因:" + e.getMessage());
                }
            }
            return R.ok();
        }
@@ -1157,7 +1178,7 @@
     */
    @Override
    public R listComMngUserTag(Long communityId) {
        List<ComMngUserTagDO> comMngUserTagDOS = comMngUserTagDAO.selectList(new QueryWrapper<ComMngUserTagDO>().lambda().eq(ComMngUserTagDO::getCommunityId, communityId));
        List<ComMngUserTagDO> comMngUserTagDOS = comMngUserTagDAO.selectList(new QueryWrapper<ComMngUserTagDO>().or().lambda().eq(ComMngUserTagDO::getSysFlag,1).or().eq(ComMngUserTagDO::getCommunityId, communityId));
        if (ObjectUtils.isEmpty(comMngUserTagDOS)) {
            return R.fail();
        }
@@ -1928,6 +1949,48 @@
            sysUserRoleDO.setUserId(sysUserDO.getUserId());
            sysUserRoleDO.setRoleId(roleId);
            sysUserRoleDAO.insert(sysUserRoleDO);
            //关联市平台网格员
            if(eventGridMemberAddDTO.getLcMemberId() != null){
                LcCompareCodeMemberDO compareCodeMemberDO = lcCompareMemberCodeMapper.selectOne(new QueryWrapper<LcCompareCodeMemberDO>().lambda()
                        .eq(LcCompareCodeMemberDO::getLcGridMemberId,eventGridMemberAddDTO.getLcMemberId()));
                if(compareCodeMemberDO != null){
                    compareCodeMemberDO.setLocalGridMemberId(sysUserDO.getUserId().toString());
                    compareCodeMemberDO.setGridMemberName(sysUserDO.getNickName());
                    compareCodeMemberDO.setUpdateAt(new Date());
                    lcCompareMemberCodeMapper.updateById(compareCodeMemberDO);
                }else{
                    compareCodeMemberDO = new LcCompareCodeMemberDO();
                    compareCodeMemberDO.setId(Snowflake.getId());
                    compareCodeMemberDO.setLocalGridMemberId(sysUserDO.getUserId().toString());
                    compareCodeMemberDO.setGridMemberName(sysUserDO.getNickName());
                    compareCodeMemberDO.setLcGridMemberId(eventGridMemberAddDTO.getLcMemberId());
                    compareCodeMemberDO.setLcBindUserId(eventGridMemberAddDTO.getLcBindUserId());
                    compareCodeMemberDO.setLcGridMemberName(eventGridMemberAddDTO.getLcMemberName());
                    compareCodeMemberDO.setCreateAt(new Date());
                    lcCompareMemberCodeMapper.insert(compareCodeMemberDO);
                }
            }
            //网格员关联楼栋
            if(eventGridMemberAddDTO.getBuildingIds() != null && !eventGridMemberAddDTO.getBuildingIds().isEmpty()){
                List<EventGridMemberBuildingRelationDO> buildingRelationList = new ArrayList<>();
                eventGridMemberAddDTO.getBuildingIds().forEach(buildingId -> {
                    Map<String,Long> resultMap = this.userDao.getBuilding(buildingId);
                    if(resultMap != null){
                        EventGridMemberBuildingRelationDO buildingRelationDO = new EventGridMemberBuildingRelationDO();
                        buildingRelationDO.setBuildingId(buildingId);
                        buildingRelationDO.setGridMemberId(sysUserDO.getUserId());
                        buildingRelationDO.setVillageId(Long.parseLong(resultMap.get("village_id").toString()));
                        buildingRelationDO.setCommunityId(Long.parseLong(resultMap.get("act_id").toString()));
                        buildingRelationDO.setCreateAt(new Date());
                        buildingRelationList.add(buildingRelationDO);
                    }
                });
                if(!buildingRelationList.isEmpty()){
                    buildingRelationService.saveBatch(buildingRelationList);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("新增后台用户报错【{}】", e.getMessage());
@@ -1951,7 +2014,31 @@
     */
    @Override
    public R getGridMemberList(PageEventGridMemberRelationDTO memberRelationDTO){
        return R.ok(userDao.getGridMemberList(new Page(memberRelationDTO.getPageNum(),memberRelationDTO.getPageSize()),memberRelationDTO));
        IPage<GridMemberVO> gridMemberPage = userDao.getGridMemberList(new Page(memberRelationDTO.getPageNum()
                ,memberRelationDTO.getPageSize()),memberRelationDTO);
        if(!gridMemberPage.getRecords().isEmpty()){
            gridMemberPage.getRecords().forEach(gridMember -> {
                //查询网格员关联市平台网格员id
                Map<String,String> lcMemberMap = this.userDao.getLcMemberId(gridMember.getUserId());
                if(lcMemberMap != null){
                    gridMember.setLcMemberId(lcMemberMap.get("lc_grid_member_id"));
                    gridMember.setLcMemberName(lcMemberMap.get("lc_grid_member_name"));
                    gridMember.setLcBindUserId(lcMemberMap.get("lc_bind_user_id"));
                }
                //查询网格员关联楼栋信息
                List<GridMemberBuildingVO> memberBuildingList = eventGridMemberBuildingRelationMapper.getGridMemberBuildingRelation(gridMember.getUserId());
                if(!memberBuildingList.isEmpty()){
                    memberBuildingList.forEach(memberBuilding -> {
                        if(!memberBuilding.getBuildingName().contains("栋")){
                            memberBuilding.setBuildingName(memberBuilding.getBuildingName() + "栋");
                        }
                    });
                    gridMember.setMemberBuildingList(memberBuildingList);
                }
            });
        }
        return R.ok(gridMemberPage);
    }
    /**
@@ -1960,6 +2047,7 @@
     * @return  修改结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R editGridUser(EventGridMemberEditAdminDTO gridMemberDTO){
        if(gridMemberDTO.getGridMemberId() == null){
@@ -1983,6 +2071,54 @@
        int insert = 0;
        try {
            insert = userDao.updateById(sysUserDO);
            //清除原本关联网格员信息
            this.userDao.delLcMember(sysUserDO.getUserId());
            //关联市平台网格员
            if(gridMemberDTO.getLcMemberId() != null){
                //关联现有的网格员信息
                LcCompareCodeMemberDO compareCodeMemberDO = lcCompareMemberCodeMapper.selectOne(new QueryWrapper<LcCompareCodeMemberDO>().lambda()
                        .eq(LcCompareCodeMemberDO::getLcGridMemberId,gridMemberDTO.getLcMemberId()));
                if(compareCodeMemberDO != null){
                    compareCodeMemberDO.setLocalGridMemberId(sysUserDO.getUserId().toString());
                    compareCodeMemberDO.setGridMemberName(sysUserDO.getNickName());
                    compareCodeMemberDO.setUpdateAt(new Date());
                    lcCompareMemberCodeMapper.updateById(compareCodeMemberDO);
                }else{
                    compareCodeMemberDO = new LcCompareCodeMemberDO();
                    compareCodeMemberDO.setId(Snowflake.getId());
                    compareCodeMemberDO.setLocalGridMemberId(sysUserDO.getUserId().toString());
                    compareCodeMemberDO.setGridMemberName(sysUserDO.getNickName());
                    compareCodeMemberDO.setLcGridMemberId(gridMemberDTO.getLcMemberId());
                    compareCodeMemberDO.setLcBindUserId(gridMemberDTO.getLcBindUserId());
                    compareCodeMemberDO.setLcGridMemberName(gridMemberDTO.getLcMemberName());
                    compareCodeMemberDO.setCreateAt(new Date());
                    lcCompareMemberCodeMapper.insert(compareCodeMemberDO);
                }
            }
            //清除原网格员与楼栋关联关系
            this.userDao.delGridMemberRelation(sysUserDO.getUserId());
            //新增网格员关联楼栋
            if(gridMemberDTO.getBuildingIds() != null && !gridMemberDTO.getBuildingIds().isEmpty()){
                List<EventGridMemberBuildingRelationDO> buildingRelationList = new ArrayList<>();
                gridMemberDTO.getBuildingIds().forEach(buildingId -> {
                    Map<String,Long> resultMap = this.userDao.getBuilding(buildingId);
                    if(resultMap != null){
                        EventGridMemberBuildingRelationDO buildingRelationDO = new EventGridMemberBuildingRelationDO();
                        buildingRelationDO.setBuildingId(buildingId);
                        buildingRelationDO.setGridMemberId(sysUserDO.getUserId());
                        buildingRelationDO.setVillageId(Long.parseLong(resultMap.get("village_id").toString()));
                        buildingRelationDO.setCommunityId(Long.parseLong(resultMap.get("act_id").toString()));
                        buildingRelationDO.setCreateAt(new Date());
                        buildingRelationList.add(buildingRelationDO);
                    }
                });
                if(!buildingRelationList.isEmpty()){
                    buildingRelationService.saveBatch(buildingRelationList);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("修改网格员用户报错【{}】", e.getMessage());
@@ -2039,6 +2175,7 @@
        return R.ok();
    }
    @Override
    public R noTips(Long userId){
        SysUserDO userDO = this.userDao.selectById(userId);
        if(userDO != null){
@@ -2049,4 +2186,62 @@
        }
        return R.fail();
    }
    /**
     * 查询社区的收益说明
     * @param communityId   社区id
     * @return  收益说明
     */
    @Override
    public R listAgreements(Long communityId){
        List<SysUserAgreementDO> sysUserAgreementDOS = sysUserAgreementDAO.selectList(new LambdaQueryWrapper<SysUserAgreementDO>()
                .eq(SysUserAgreementDO::getCommunityId,communityId).eq(SysUserAgreementDO::getType,5));
        if (sysUserAgreementDOS.isEmpty()) {
            SysUserAgreementDO agreementDO = new SysUserAgreementDO();
            agreementDO.setCommunityId(communityId);
            agreementDO.setName("收益说明");
            agreementDO.setType(5);
            agreementDO.setCreateAt(new Date());
            agreementDO.setContent(Constants.PROFIT_EXPLAIN);
            sysUserAgreementDAO.insert(agreementDO);
            sysUserAgreementDOS.add(agreementDO);
        }
        List<SysUserAgreementVO> sysUserAgreementVOS = new ArrayList<>();
        sysUserAgreementDOS.forEach(sysUserAgreementDO -> {
            SysUserAgreementVO sysUserAgreementVO = new SysUserAgreementVO();
            BeanUtils.copyProperties(sysUserAgreementDO, sysUserAgreementVO);
            sysUserAgreementVOS.add(sysUserAgreementVO);
        });
        return R.ok(sysUserAgreementVOS);
    }
    @Override
    public R getGridIsOk(Long userId){
        Integer count = this.userDao.getGridIsOk(userId);
        if(count > 0){
            return R.ok(count);
        }else{
            return R.fail();
        }
    }
    @Override
    public R getGridsMemberList(Long communityId){
        return R.ok(this.userDao.getGridsMemberList(communityId));
    }
    /**
     * 根据用户id查询用户openid
     * @param userId    用户id
     * @return  openid
     */
    @Override
    public R getUserOpenId(Long userId){
        SysUserDO userDO = this.userDao.selectById(userId);
        if(userDO != null){
            return R.ok(userDO.getOpenid());
        }
        return R.fail();
    }
}