lin
2024-04-23 6a63e7a6d94ee83ca833f8dd513c1c94fcd1c5ba
空指针问题
2 files modified
121 ■■■■■ changed files
src/main/java/org/springblade/modules/discuss/service/impl/UserTopicsServiceImpl.java 20 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/house/service/impl/HouseServiceImpl.java 101 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/discuss/service/impl/UserTopicsServiceImpl.java
@@ -27,9 +27,11 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.common.constant.CommonConstant;
import org.springblade.common.utils.SpringUtils;
import org.springblade.core.redis.cache.BladeRedis;
@@ -51,8 +53,8 @@
import org.springblade.modules.district.entity.DistrictEntity;
import org.springblade.modules.district.service.IDistrictService;
import org.springblade.modules.house.entity.HouseholdEntity;
import org.springblade.modules.house.excel.HouseHoldExcel;
import org.springblade.modules.house.service.IHouseholdService;
import org.springblade.modules.house.service.impl.HouseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -75,6 +77,9 @@
    @Resource
    private ITopicsService topicsService;
    public static final String SMS_VALIDATE_PHONE = "sms:validate:code:";
    private static final Logger logger = LoggerFactory.getLogger(UserTopicsServiceImpl.class);
    @Autowired
    private BladeRedis redisTemplate;
@@ -117,7 +122,7 @@
        PublicDiscussEntity discussEntity = bean.getOne(Wrappers.<PublicDiscussEntity>lambdaQuery().eq(PublicDiscussEntity::getArticleId, topicsList.get(0).getArticleId()));
        // 判断是否在开始和结束时间内
        if (discussEntity.getStartTime().getTime() > System.currentTimeMillis() || discussEntity.getEndTime().getTime() < System.currentTimeMillis()) {
            return "目前不在投票时间内,投票时间:"+ DateUtil.formatDateTime(discussEntity.getStartTime()) +" 至 "+DateUtil.formatDateTime(discussEntity.getEndTime());
            return "目前不在投票时间内,投票时间:" + DateUtil.formatDateTime(discussEntity.getStartTime()) + " 至 " + DateUtil.formatDateTime(discussEntity.getEndTime());
        }
        if (StringUtils.isNotBlank(topics.getPhone())) {
            if (StringUtils.isBlank(topics.getCode())) {
@@ -140,7 +145,10 @@
            .eq(HouseholdEntity::getAssociatedUserId, AuthUtil.getUserId())
            .eq(HouseholdEntity::getIsDeleted, 0)
            .last("limit 1"));
        if (ObjectUtils.isEmpty(householdEntity)) {
            logger.error("未查询到住户信息!", JSON.toJSONString(topics));
            return "未查询到住户信息!";
        }
        // 一户一票
        if (discussEntity.getVoteRestrictions().equals(CommonConstant.NUMBER_ONE)) {
            long count = count(Wrappers.<UserTopicsEntity>lambdaQuery()
@@ -352,13 +360,13 @@
     * @return 返回一个JSONArray对象,包含解析后的区域ID。
     * @throws IllegalArgumentException 如果区域ID字符串为空或空白字符串,抛出此异常。
     */
    private List<String>  validateAndParseDistrictId(String districtIdStr) throws IllegalArgumentException {
    private List<String> validateAndParseDistrictId(String districtIdStr) throws IllegalArgumentException {
        // 验证区域ID字符串是否为空
        if (StringUtils.isBlank(districtIdStr)) {
            throw new IllegalArgumentException("区域ID不能为空");
        }
        // 解析区域ID字符串为JSONArray对象
        return  Arrays.asList(districtIdStr.split(","));
        return Arrays.asList(districtIdStr.split(","));
    }
    private List<String> processDistrictIds(IDistrictService districtService, List<String> districtIds) {
src/main/java/org/springblade/modules/house/service/impl/HouseServiceImpl.java
@@ -22,8 +22,12 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxl.job.core.server.EmbedServer;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.common.cache.SysCache;
import org.springblade.common.param.CommonParamSet;
import org.springblade.common.utils.IdUtils;
@@ -80,6 +84,8 @@
public class HouseServiceImpl extends ServiceImpl<HouseMapper, HouseEntity> implements IHouseService {
    private static final Logger logger = LoggerFactory.getLogger(HouseServiceImpl.class);
    @Autowired
    private IGridService gridService;
@@ -99,11 +105,11 @@
    public IPage<HouseVO> selectHousePage(IPage<HouseVO> page, HouseVO house) {
//        List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId());
//        Integer isAdministrator = AuthUtil.isAdministrator() == true ? 1 : 2;
        CommonParamSet commonParamSet = new CommonParamSet().invoke(HouseVO.class,house);
        CommonParamSet commonParamSet = new CommonParamSet().invoke(HouseVO.class, house);
        List<HouseVO> houseVOS = baseMapper.selectHousePage(page, house,
            commonParamSet.getRegionChildCodesList(),commonParamSet.getGridCodeList(), commonParamSet.getIsAdministrator()
            );
            commonParamSet.getRegionChildCodesList(), commonParamSet.getGridCodeList(), commonParamSet.getIsAdministrator()
        );
        return page.setRecords(houseVOS);
    }
@@ -115,6 +121,14 @@
     */
    @Override
    public HouseVO getHouseDetail(HouseVO house) {
        if (house == null) {
            logger.error("house是空值", house);
            return new HouseVO();
        }
        if (StringUtils.isBlank(house.getHouseCode()) && ObjectUtils.isEmpty(house.getId())) {
            logger.error("house.HouseCode是空值", house);
            return new HouseVO();
        }
        return baseMapper.getHouseDetail(house);
    }
@@ -220,7 +234,7 @@
        if (null != houseParam.getRoleName() && !houseParam.getRoleName().equals("")) {
            if (houseParam.getRoleName().equals("网格员")) {
                // 查询对应的房屋地址code
                stringList = gridService.getAddressCodeListByUserId(AuthUtil.getUserId(),null);
                stringList = gridService.getAddressCodeListByUserId(AuthUtil.getUserId(), null);
            }
        }
        return stringList;
@@ -266,9 +280,9 @@
            if (Strings.isBlank(houseAndHoldExcel.getHouseName())) {
                // 查询地址总表对应的数据
                QueryWrapper<DoorplateAddressEntity> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("address_code",houseAndHoldExcel.getHouseCode());
                queryWrapper.eq("address_code", houseAndHoldExcel.getHouseCode());
                DoorplateAddressEntity addressEntity = doorplateAddressService.getOne(queryWrapper);
                if (null!=addressEntity){
                if (null != addressEntity) {
                    houseEntity.setHouseName(addressEntity.getAddressName());
                    houseEntity.setAddress(addressEntity.getAddressName());
                    houseEntity.setDistrictCode(addressEntity.getAoiCode());
@@ -276,7 +290,7 @@
                    houseEntity.setLng(addressEntity.getX());
                    houseEntity.setLat(addressEntity.getY());
                }
            }else {
            } else {
                houseEntity.setHouseName(houseAndHoldExcel.getHouseName());
                houseEntity.setAddress(houseAndHoldExcel.getHouseName());
            }
@@ -313,17 +327,17 @@
                houseEntity.setSource(2);
            }
            // 网格处理
            importGridHandle(houseAndHoldExcel,houseEntity);
            importGridHandle(houseAndHoldExcel, houseEntity);
            // 新增
            save(houseEntity);
        }else {
        } else {
            // 更新
            if (Strings.isBlank(houseAndHoldExcel.getHouseName())) {
                // 查询地址总表对应的数据
                QueryWrapper<DoorplateAddressEntity> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("address_code",houseAndHoldExcel.getHouseCode());
                queryWrapper.eq("address_code", houseAndHoldExcel.getHouseCode());
                DoorplateAddressEntity addressEntity = doorplateAddressService.getOne(queryWrapper);
                if (null!=addressEntity){
                if (null != addressEntity) {
                    one.setHouseName(addressEntity.getAddressName());
                    one.setAddress(addressEntity.getAddressName());
                    one.setDistrictCode(addressEntity.getAoiCode());
@@ -331,7 +345,7 @@
                    one.setLng(addressEntity.getX());
                    one.setLat(addressEntity.getY());
                }
            }else {
            } else {
                one.setHouseName(houseAndHoldExcel.getHouseName());
                one.setAddress(houseAndHoldExcel.getHouseName());
            }
@@ -349,7 +363,7 @@
            one.setArea(houseAndHoldExcel.getArea());
            one.setPropertyPrice(houseAndHoldExcel.getPropertyPrice());
            // 网格处理
            importGridHandle(houseAndHoldExcel,one);
            importGridHandle(houseAndHoldExcel, one);
            // 更新
            updateById(one);
        }
@@ -401,7 +415,7 @@
                    // 身份证类型为居民身份证
                    householdEntity.setCardType(111);
                    householdEntity.setIdCard(houseAndHoldExcel.getIdCard());
                }else {
                } else {
                    householdEntity.setIdCard(houseAndHoldExcel.getIdCard());
                }
            }
@@ -522,7 +536,7 @@
                    // 身份证类型为居民身份证
                    one.setCardType(111);
                    one.setIdCard(houseAndHoldExcel.getIdCard());
                }else {
                } else {
                    one.setIdCard(houseAndHoldExcel.getIdCard());
                }
            }
@@ -604,7 +618,7 @@
            boolean update = householdService.updateById(one);
            if (update) {
                // 住户标签处理
                householdLabelHandle(houseAndHoldExcel,one);
                householdLabelHandle(houseAndHoldExcel, one);
            }
        }
    }
@@ -612,15 +626,16 @@
    /**
     * 导入是网格数据绑定处理
     *
     * @param houseAndHoldExcel
     * @param houseEntity
     */
    public void importGridHandle(HouseAndHoldExcel houseAndHoldExcel, HouseEntity houseEntity) {
        if (!Strings.isBlank(houseAndHoldExcel.getCommunityName()) &&
            !Strings.isBlank(houseAndHoldExcel.getGridName())){
            !Strings.isBlank(houseAndHoldExcel.getGridName())) {
            // 查询对应的网格信息
            GridEntity gridEntity = gridService.getGridInfoByParam(houseAndHoldExcel.getCommunityName(),houseAndHoldExcel.getGridName());
            if (null!=gridEntity){
            GridEntity gridEntity = gridService.getGridInfoByParam(houseAndHoldExcel.getCommunityName(), houseAndHoldExcel.getGridName());
            if (null != gridEntity) {
                // 设置场所范围
                houseEntity.setGridId(gridEntity.getId());
                houseEntity.setGridCode(gridEntity.getGridCode());
@@ -630,14 +645,15 @@
                gridRangeEntity.setGridCode(gridEntity.getGridCode());
                gridRangeEntity.setHouseCode(houseEntity.getHouseCode());
                UpdateWrapper<GridRangeEntity> updateWrapper = new UpdateWrapper<>();
                updateWrapper.eq("house_code",houseEntity.getHouseCode());
                gridRangeService.update(gridRangeEntity,updateWrapper);
                updateWrapper.eq("house_code", houseEntity.getHouseCode());
                gridRangeService.update(gridRangeEntity, updateWrapper);
            }
        }
    }
    /**
     * 住户标签处理
     *
     * @param houseAndHoldExcel
     * @param householdEntity
     */
@@ -653,11 +669,11 @@
                if (one1 != null) {
                    // 判断是否已存在关联关系,没有则新增
                    QueryWrapper<UserHouseLabelEntity> wrapper = new QueryWrapper<>();
                    wrapper.eq("label_id",one1.getId())
                        .eq("house_code",householdEntity.getHouseCode())
                        .eq("household_id",householdEntity.getId());
                    wrapper.eq("label_id", one1.getId())
                        .eq("house_code", householdEntity.getHouseCode())
                        .eq("household_id", householdEntity.getId());
                    UserHouseLabelEntity houseLabelEntity = bean.getOne(wrapper);
                    if (null==houseLabelEntity) {
                    if (null == houseLabelEntity) {
                        UserHouseLabelEntity userHouseLabelEntity = new UserHouseLabelEntity();
                        userHouseLabelEntity.setLabelId(BigDecimal.valueOf(one1.getId()).longValue());
                        userHouseLabelEntity.setHouseholdId(householdEntity.getId());
@@ -775,7 +791,7 @@
        if (null != householdEntity.getPhoneNumber() && !householdEntity.getPhoneNumber().equals("")) {
            //根据手机号查询库里的数据
            List<User> list = userService.getUserListByPhoneOrAccount(householdEntity.getPhoneNumber());
            if (list.size()>0) {
            if (list.size() > 0) {
                User user = list.get(0);
                //如果用户存在,则该用户id绑定住户
                householdEntity.setAssociatedUserId(user.getId());
@@ -859,13 +875,14 @@
                commonParamSet.getRegionChildCodesList(),
                commonParamSet.getIsAdministrator(),
                map.get("code").toString());
            map.put("child",code);
            map.put("child", code);
        }
        return list;
    }
    /**
     * 房屋网格处理
     *
     * @return
     */
    @Override
@@ -876,7 +893,7 @@
        for (HouseEntity houseEntity : houseEntityList) {
            String point = "'POINT(" + houseEntity.getLng() + " " + houseEntity.getLat() + ")'";
            List<GridEntity> gridEntityList = SpringUtils.getBean(IGridService.class).spatialAnalysis(point);
            if (gridEntityList.size()>0){
            if (gridEntityList.size() > 0) {
                houseEntity.setGridCode(gridEntityList.get(0).getGridCode());
                houseEntity.setGridId(gridEntityList.get(0).getId());
                // 更新
@@ -889,6 +906,7 @@
    /**
     * 房屋警格处理
     *
     * @return
     */
    @Override
@@ -899,7 +917,7 @@
        for (HouseEntity houseEntity : houseEntityList) {
            String point = "'POINT(" + houseEntity.getLng() + " " + houseEntity.getLat() + ")'";
            List<PoliceAffairsGridEntity> policeAffairsGridEntityList = SpringUtils.getBean(IPoliceAffairsGridService.class).spatialAnalysis(point);
            if (policeAffairsGridEntityList.size()>0){
            if (policeAffairsGridEntityList.size() > 0) {
                houseEntity.setJwGridCode(policeAffairsGridEntityList.get(0).getJwGridCode());
                // 更新
                updateById(houseEntity);
@@ -910,14 +928,15 @@
    /**
     * 房屋画像统计-按房屋标签统计
     *
     * @param house
     * @return
     */
    @Override
    public List<Map<String,Object>> getHouseLabelStatistic(HouseVO house) {
    public List<Map<String, Object>> getHouseLabelStatistic(HouseVO house) {
        CommonParamSet commonParamSet = new CommonParamSet<>().invoke(HouseVO.class, house);
        // 按房屋标签统计
        List<Map<String,Object>> list = baseMapper.getHouseLabelStatistic(house,
        List<Map<String, Object>> list = baseMapper.getHouseLabelStatistic(house,
            commonParamSet.getIsAdministrator(),
            commonParamSet.getRegionChildCodesList(),
            commonParamSet.getGridCodeList());
@@ -927,6 +946,7 @@
    /**
     * 查询对应的社区编号
     *
     * @param id
     * @return
     */
@@ -937,6 +957,7 @@
    /**
     * 查询所有房屋总数
     *
     * @return
     */
    @Override
@@ -946,17 +967,19 @@
    /**
     * 查询所有的房屋
     *
     * @param i
     * @param size
     * @return
     */
    @Override
    public List<HouseVO> getAllList(int i, int size) {
        return baseMapper.getAllList(i,size);
        return baseMapper.getAllList(i, size);
    }
    /**
     * 房屋标签初始化处置-根据有租客的,初始成出租,有业主没租客的初始化成自主,业主都没的就是闲置
     *
     * @param house
     * @return
     */
@@ -976,19 +999,19 @@
                houseLabelEntity.setHouseCode(houseEntity.getHouseCode());
                houseLabelEntity.setLableType(2);
                houseLabelEntity.setCreateTime(new Date());
                if (houseEntity.getStatus()==1) {
                if (houseEntity.getStatus() == 1) {
                    // 闲置
                    houseLabelEntity.setColor("green");
                    houseLabelEntity.setLabelName("闲置");
                    houseLabelEntity.setLabelId(1037L);
                }
                if (houseEntity.getStatus()==2) {
                if (houseEntity.getStatus() == 2) {
                    // 自住
                    houseLabelEntity.setColor("blue");
                    houseLabelEntity.setLabelName("自住");
                    houseLabelEntity.setLabelId(1038L);
                }
                if (houseEntity.getStatus()==3) {
                if (houseEntity.getStatus() == 3) {
                    // 出租
                    houseLabelEntity.setColor("yellow");
                    houseLabelEntity.setLabelName("出租");
@@ -996,14 +1019,14 @@
                }
                // 查询当前房屋是否已有,有则更新,无则新增
                QueryWrapper<UserHouseLabelEntity> wrapper = new QueryWrapper<>();
                wrapper.eq("house_code",houseEntity.getHouseCode())
                    .eq("lable_type",2);
                wrapper.eq("house_code", houseEntity.getHouseCode())
                    .eq("lable_type", 2);
                UserHouseLabelEntity userHouseLabelEntity = userHouseLabelService.getOne(wrapper);
                if (null!=userHouseLabelEntity){
                if (null != userHouseLabelEntity) {
                    // 更新
                    houseLabelEntity.setId(userHouseLabelEntity.getId());
                    userHouseLabelService.updateById(houseLabelEntity);
                }else {
                } else {
                    // 新增
                    userHouseLabelService.save(houseLabelEntity);
                }