44323
2023-12-04 fd83395529437e0c02b8d69b039fe52d40a4ec62
guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/HouseResourceService.java
@@ -9,9 +9,14 @@
import com.stylefeng.guns.modular.system.dao.HouseResourceMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.warpper.PointLocation;
import com.stylefeng.guns.modular.system.warpper.req.AddHouseReq;
import com.stylefeng.guns.modular.system.warpper.req.HouseQuery;
import com.stylefeng.guns.modular.system.warpper.req.SearchHouseResourceReq;
import com.stylefeng.guns.modular.system.warpper.req.UserInfoQuery;
import com.stylefeng.guns.modular.system.warpper.res.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
@@ -27,6 +32,7 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@@ -49,6 +55,8 @@
    private ICollectionHouseResourceService collectionHouseResourceService;
    @Resource
    private MongoTemplate mongoTemplate;
    @Autowired
    private IHousingDemandService housingDemandService;
@@ -65,27 +73,37 @@
        if(req.getType() == 1){
            fillSearchHistory(req);
        }
        //区域
        List<Integer> districtIds = null;
        List<Integer> cityIds = null;
        if(StringUtils.hasLength(req.getDistrict())){
            cityIds = new ArrayList<>();
            districtIds = new ArrayList<>();
            JSONArray jsonArray = JSON.parseArray(req.getDistrict());
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                Integer cityId = jsonObject.getInteger("cityId");
                Integer districtId = jsonObject.getInteger("districtId");
                //不限区域
                if(0 == districtId || null == districtId){
                    List<Region> regions = regionService.selectList(new EntityWrapper<Region>().eq("parent_id", cityId));
                    districtIds.addAll(regions.stream().map(Region::getId).collect(Collectors.toList()));
        List<Integer> districtIds = new ArrayList<>();
        List<Integer> cityIds = new ArrayList<>();
        if (req.getDistrict() != null &&(!req.getDistrict().equals("")) ){
            // 一级id
            Integer integer = Integer.valueOf(req.getDistrict());
            districtIds.add(integer);
            if (req.getArea()!=null && (!req.getArea().equals(""))){
                String[] split = req.getArea().split(",");
                for (String s : split) {
                    cityIds.add(Integer.valueOf(s));
                }
                cityIds.add(cityId);
                districtIds.add(districtId);
            }
        }
//        if(StringUtils.hasLength(req.getDistrict())){
//            cityIds = new ArrayList<>();
//            districtIds = new ArrayList<>();
//            JSONArray jsonArray = JSON.parseArray(req.getDistrict());
//            for (int i = 0; i < jsonArray.size(); i++) {
//                JSONObject jsonObject = jsonArray.getJSONObject(i);
//                Integer cityId = jsonObject.getInteger("cityId");
//                Integer districtId = jsonObject.getInteger("districtId");
//                //不限区域
//                if(0 == districtId || null == districtId){
//                    List<Region> regions = regionService.selectList(new EntityWrapper<Region>().eq("parent_id", cityId));
//                    districtIds.addAll(regions.stream().map(Region::getId).collect(Collectors.toList()));
//                }
//                cityIds.add(cityId);
//                districtIds.add(districtId);
//            }
//        }
        //价格范围
        Double saleAmountStart = null;
@@ -128,7 +146,8 @@
        AppUser appUser = appUserService.getAppUser();
        if(null != appUser){
            //获取历史搜索数据
            SearchHistoryCondition searchHistoryCondition = searchHistoryConditionService.selectOne(new EntityWrapper<SearchHistoryCondition>().eq("app_user_id", appUser.getId()));
            SearchHistoryCondition searchHistoryCondition = searchHistoryConditionService
                    .selectOne(new EntityWrapper<SearchHistoryCondition>().eq("app_user_id", appUser.getId()));
            if(null == searchHistoryCondition){
                //没有历史记录,将现有记录添加进去
                searchHistoryCondition = new SearchHistoryCondition();
@@ -144,11 +163,11 @@
                if(ToolUtil.isEmpty(req.getDistrict()) && ToolUtil.isEmpty(req.getSaleAmount()) &&
                        ToolUtil.isEmpty(req.getHouseModel()) && ToolUtil.isEmpty(req.getElevator()) &&
                        ToolUtil.isEmpty(req.getHouseTypeId())){
                    req.setDistrict(searchHistoryCondition.getDistrict());
                    req.setSaleAmount(searchHistoryCondition.getPrice());
                    req.setHouseModel(searchHistoryCondition.getHouseModels());
                    req.setElevator(searchHistoryCondition.getElevator());
                    req.setHouseTypeId(searchHistoryCondition.getHouseTypeIds());
//                    req.setDistrict(searchHistoryCondition.getDistrict());
//                    req.setSaleAmount(searchHistoryCondition.getPrice());
//                    req.setHouseModel(searchHistoryCondition.getHouseModels());
//                    req.setElevator(searchHistoryCondition.getElevator());
//                    req.setHouseTypeId(searchHistoryCondition.getHouseTypeIds());
                }else{
                    //更新历史搜索记录
                    searchHistoryCondition.setDistrict(req.getDistrict());
@@ -190,7 +209,7 @@
        houseResourceInfoRes.setSaleAmount(houseResource.getSaleAmount());
        houseResourceInfoRes.setHouseModel(houseResource.getHouseModel());
        houseResourceInfoRes.setRentalDuration(houseResource.getRentalDuration());
        houseResourceInfoRes.setSaleDate(sdf.format(houseResource.getSaleDate()));
        houseResourceInfoRes.setSaleDate(houseResource.getStartTime());
        houseResourceInfoRes.setHousePhoto(houseResource.getHousePhoto());
        HouseType houseType = houseTypeService.selectById(houseResource.getHouseTypeId());
        houseResourceInfoRes.setHouseType(houseType.getName());
@@ -211,7 +230,9 @@
        houseResourceInfoRes.setNickname(appUser1.getNickname());
        houseResourceInfoRes.setUserType(appUser1.getUserType());
        houseResourceInfoRes.setInsertTime(sdf.format(houseResource.getInsertTime()));
        houseResourceInfoRes.setUpdateTime(sdf.format(houseResource.getUpdateTime()));
        if (houseResource.getUpdateTime()!=null){
            houseResourceInfoRes.setUpdateTime(sdf.format(houseResource.getUpdateTime()));
        }
        houseResourceInfoRes.setCode(houseResource.getCode());
        int collectionTimes = collectionHouseResourceService.selectCount(new EntityWrapper<CollectionHouseResource>().eq("house_resource_id", id));
        houseResourceInfoRes.setCollectionTimes(collectionTimes);
@@ -252,6 +273,7 @@
        Query query = Query.query(Criteria.where("geoJsonPoint").withinSphere(circle));
        List<PointLocation> pointLocations = mongoTemplate.find(query, PointLocation.class);
        List<Integer> ids = pointLocations.stream().map(PointLocation::getHouseId).collect(Collectors.toList());
        if (ids.size()!= 0){
        List<HouseResource> houseResources = this.selectBatchIds(ids);
        List<SearchHouseResourceListRes> list = new ArrayList<>();
        //遍历解析出返回数据
@@ -276,7 +298,11 @@
            searchHouseResourceListRes.setKeepPet(resource.getKeepPet());
            list.add(searchHouseResourceListRes);
        }
            return list;
        }
        List<SearchHouseResourceListRes> list = new ArrayList<>();
        return list;
    }
@@ -295,6 +321,98 @@
        return contactInformationRes;
    }
    @Override
    public SearchHouseResourceRes listHouse(HouseQuery query) {
        SearchHouseResourceRes res = new SearchHouseResourceRes();
        res.setList(this.baseMapper.listHouse(query));
        res.setTotal(res.getList().size());
        return res;
    }
    @Override
    public ResultUtil addHouse(AddHouseReq req) {
        Integer appUserId = appUserService.getAppUser().getId();
        AppUser appUser = appUserService.selectOne(new EntityWrapper<AppUser>()
                .eq("id", appUserId)
                .eq("audit_status", 2)
                .eq("status", 1));
        if (appUser!=null){
            if (appUser.getAgentLicenceCode()==null){
                // 未认证 只能能发布三条房源信息
                List<HouseResource> houseResources = this.selectList(new EntityWrapper<HouseResource>()
                        .eq("app_user_id", appUserId)
                        .eq("is_delete", 1)
                        .eq("status", 1)
                );
                if (houseResources.size()>=3){
                    return ResultUtil.error("中介账号未认证,只能同时上架3条房源信息");
                }
            }else{
                // 已经认证 只能能发布20条房源信息
                List<HouseResource> houseResources = this.selectList(new EntityWrapper<HouseResource>()
                        .eq("app_user_id", appUserId)
                        .eq("is_delete", 1)
                        .eq("status", 1)
                );
                if (houseResources.size()>=20){
                    return ResultUtil.error("当前中介账号只能同时上架20条房源信息");
                }
            }
            HouseResource houseResource = new HouseResource();
            BeanUtils.copyProperties(req,houseResource);
            System.err.println(houseResource);
            houseResource.setInsertTime(new Date());
            houseResource.setAuthStatus(1);
            houseResource.setIsDelete(0);
            houseResource.setInsertUserId(appUserId);
            houseResource.setViewsNumber(0);
            houseResource.setStatus(0);
            houseResource.setLeaseTime(req.getTime());
            houseResource.setFirmHouse(req.getFirmHouse());
            if (req.getTime().contains("年")){
                houseResource.setRentalDuration(2);
            }else{
                houseResource.setRentalDuration(1);
            }
            this.baseMapper.insert(houseResource);
            return ResultUtil.success();
        }
        return ResultUtil.success();
    }
    @Override
    public ResultUtil confirm(Integer userType) {
        AppUser appUser = appUserService.getAppUser();
        if (userType == 3){
            // 需要下架所有个人房源和求房源信息
            List<HouseResource> list = this.selectList(new EntityWrapper<HouseResource>()
                    .eq("app_user_id", appUser.getId()));
            for (HouseResource houseResource : list) {
                houseResource.setStatus(0);
                this.baseMapper.updateById(houseResource);
            }
            List<HousingDemand> list2 = housingDemandService.selectList(new EntityWrapper<HousingDemand>()
                    .eq("app_user_id", appUser.getId()));
            for (HousingDemand housingDemand : list2) {
                housingDemand.setStatus(0);
                housingDemandService.updateById(housingDemand);
            }
//            housingDemandService.updateBatchById(list2);
        }
        appUser.setUserType(userType);
        appUserService.updateById(appUser);
        return ResultUtil.success();
    }
    @Override
    public List<CollectListRes> collect(List<Integer> ids) {
      return this.baseMapper.collect(ids);
    }
    public List<CollectListRes> release(UserInfoQuery query, List<Integer> collect) {
        return this.baseMapper.release(query,collect);
    }
}