10
10
import com .bubble .house .entity .param .HouseParam ;
11
11
import com .bubble .house .entity .param .PhotoParam ;
12
12
import com .bubble .house .entity .param .RentSearchParam ;
13
- import com .bubble .house .entity .result .MultiResultEntity ;
14
- import com .bubble .house .entity .result .ResultEntity ;
13
+ import com .bubble .house .entity .result .ServiceMultiResultEntity ;
14
+ import com .bubble .house .entity .result .ServiceResultEntity ;
15
15
import com .bubble .house .entity .search .MapSearchEntity ;
16
16
import com .bubble .house .repository .*;
17
17
import com .bubble .house .service .search .SearchService ;
@@ -80,9 +80,9 @@ public HouseServiceImpl(SubwayRepository subwayRepository, SubwayStationReposito
80
80
}
81
81
82
82
@ Override
83
- public ResultEntity <HouseDTO > save (HouseParam houseParam ) {
83
+ public ServiceResultEntity <HouseDTO > save (HouseParam houseParam ) {
84
84
HouseDetailEntity detail = new HouseDetailEntity ();
85
- ResultEntity <HouseDTO > subwayValidationResult = wrapperDetailInfo (detail , houseParam );
85
+ ServiceResultEntity <HouseDTO > subwayValidationResult = wrapperDetailInfo (detail , houseParam );
86
86
if (subwayValidationResult != null ) {
87
87
return subwayValidationResult ;
88
88
}
@@ -123,7 +123,7 @@ public ResultEntity<HouseDTO> save(HouseParam houseParam) {
123
123
houseDTO .setTags (tags );
124
124
}
125
125
LOGGER .info ("save house [{}] info successfully" , house .getId ());
126
- return new ResultEntity <>(true , null , houseDTO );
126
+ return new ServiceResultEntity <>(true , null , houseDTO );
127
127
}
128
128
129
129
/**
@@ -149,14 +149,14 @@ private List<HousePictureEntity> generatePictures(HouseParam houseParam, Long ho
149
149
/**
150
150
* 房源详细信息对象填充
151
151
*/
152
- private ResultEntity <HouseDTO > wrapperDetailInfo (HouseDetailEntity houseDetail , HouseParam houseParam ) {
152
+ private ServiceResultEntity <HouseDTO > wrapperDetailInfo (HouseDetailEntity houseDetail , HouseParam houseParam ) {
153
153
Optional <SubwayEntity > subwayOp = this .subwayRepository .findById (houseParam .getSubwayLineId ());
154
154
if (subwayOp .isPresent ()) {
155
155
SubwayEntity subway = subwayOp .get ();
156
156
Optional <SubwayStationEntity > subwayStationOp = this .subwayStationRepository .findById (houseParam .getSubwayStationId ());
157
157
if (!subwayStationOp .isPresent () || !subway .getId ().equals (subwayStationOp .get ().getSubwayId ())) {
158
158
LOGGER .error ("[{}] Not valid subway station!" , houseDetail .getHouseId ());
159
- return new ResultEntity <>(false , "Not valid subway station!" );
159
+ return new ServiceResultEntity <>(false , "Not valid subway station!" );
160
160
} else {
161
161
SubwayStationEntity subwayStation = subwayStationOp .get ();
162
162
@@ -175,13 +175,13 @@ private ResultEntity<HouseDTO> wrapperDetailInfo(HouseDetailEntity houseDetail,
175
175
}
176
176
} else {
177
177
LOGGER .error ("[{}] Not valid subway line!" , houseDetail .getHouseId ());
178
- return new ResultEntity <>(false , "Not valid subway line!" );
178
+ return new ServiceResultEntity <>(false , "Not valid subway line!" );
179
179
}
180
180
return null ;
181
181
}
182
182
183
183
@ Override
184
- public MultiResultEntity <HouseDTO > adminQuery (DatatableSearchParam searchBody ) {
184
+ public ServiceMultiResultEntity <HouseDTO > adminQuery (DatatableSearchParam searchBody ) {
185
185
List <HouseDTO > houseDTOS = Lists .newArrayList ();
186
186
// 分页查询
187
187
Sort sort = Sort .by (Sort .Direction .fromString (searchBody .getDirection ()), searchBody .getOrderBy ());
@@ -222,15 +222,15 @@ public MultiResultEntity<HouseDTO> adminQuery(DatatableSearchParam searchBody) {
222
222
houseDTOS .add (houseDTO );
223
223
});
224
224
225
- return new MultiResultEntity <>(houses .getTotalElements (), houseDTOS );
225
+ return new ServiceMultiResultEntity <>(houses .getTotalElements (), houseDTOS );
226
226
// return new MultiResultEntity<>(houseDTOS.size(), houseDTOS);
227
227
}
228
228
229
229
@ Override
230
- public ResultEntity <HouseDTO > findCompleteOne (Long id ) {
230
+ public ServiceResultEntity <HouseDTO > findCompleteOne (Long id ) {
231
231
Optional <HouseEntity > houseOp = houseRepository .findById (id );
232
232
if (!houseOp .isPresent ()) {
233
- return ResultEntity .notFound ();
233
+ return ServiceResultEntity .notFound ();
234
234
}
235
235
HouseDetailEntity detail = houseDetailRepository .findByHouseId (id );
236
236
List <HousePictureEntity > pictures = housePictureRepository .findAllByHouseId (id );
@@ -258,22 +258,22 @@ public ResultEntity<HouseDTO> findCompleteOne(Long id) {
258
258
result .setSubscribeStatus (subscribe .getStatus ());
259
259
}
260
260
}
261
- return ResultEntity .of (result );
261
+ return ServiceResultEntity .of (result );
262
262
}
263
263
264
264
@ Override
265
265
@ Transactional
266
- public ResultEntity update (HouseParam houseParam ) {
266
+ public ServiceResultEntity update (HouseParam houseParam ) {
267
267
Optional <HouseEntity > houseOp = this .houseRepository .findById (houseParam .getId ());
268
268
if (!houseOp .isPresent ()) {
269
- return ResultEntity .notFound ();
269
+ return ServiceResultEntity .notFound ();
270
270
}
271
271
HouseEntity house = houseOp .get ();
272
272
HouseDetailEntity detail = this .houseDetailRepository .findByHouseId (house .getId ());
273
273
if (detail == null ) {
274
- return ResultEntity .notFound ();
274
+ return ServiceResultEntity .notFound ();
275
275
}
276
- ResultEntity wrapperResult = wrapperDetailInfo (detail , houseParam );
276
+ ServiceResultEntity wrapperResult = wrapperDetailInfo (detail , houseParam );
277
277
if (wrapperResult != null ) {
278
278
return wrapperResult ;
279
279
}
@@ -293,91 +293,91 @@ public ResultEntity update(HouseParam houseParam) {
293
293
this .searchService .index (house .getId ());
294
294
}
295
295
296
- return ResultEntity .success ();
296
+ return ServiceResultEntity .success ();
297
297
}
298
298
299
299
@ Override
300
- public ResultEntity removePhoto (Long id ) {
300
+ public ServiceResultEntity removePhoto (Long id ) {
301
301
Optional <HousePictureEntity > pictureOp = this .housePictureRepository .findById (id );
302
302
if (pictureOp .isPresent ()) {
303
303
try {
304
304
Response response = this .qiNiuService .delete (pictureOp .get ().getPath ());
305
305
if (response .isOK ()) {
306
306
this .housePictureRepository .deleteById (id );
307
- return ResultEntity .success ();
307
+ return ServiceResultEntity .success ();
308
308
} else {
309
- return new ResultEntity (false , response .error );
309
+ return new ServiceResultEntity (false , response .error );
310
310
}
311
311
} catch (QiniuException e ) {
312
312
LOGGER .error ("删除七牛云图片[{}]异常" , id );
313
- return new ResultEntity (false , e .getMessage ());
313
+ return new ServiceResultEntity (false , e .getMessage ());
314
314
}
315
315
} else {
316
- return ResultEntity .notFound ();
316
+ return ServiceResultEntity .notFound ();
317
317
}
318
318
}
319
319
320
320
@ Override
321
321
@ Transactional
322
- public ResultEntity updateCover (Long coverId , Long targetId ) {
322
+ public ServiceResultEntity updateCover (Long coverId , Long targetId ) {
323
323
Optional <HousePictureEntity > coverOp = this .housePictureRepository .findById (coverId );
324
324
if (!coverOp .isPresent ()) {
325
- return ResultEntity .notFound ();
325
+ return ServiceResultEntity .notFound ();
326
326
}
327
327
this .houseRepository .updateCover (targetId , coverOp .get ().getPath ());
328
- return ResultEntity .success ();
328
+ return ServiceResultEntity .success ();
329
329
}
330
330
331
331
@ Override
332
332
@ Transactional
333
- public ResultEntity addTag (Long houseId , String tag ) {
333
+ public ServiceResultEntity addTag (Long houseId , String tag ) {
334
334
Optional <HouseEntity > houseOp = this .houseRepository .findById (houseId );
335
335
if (!houseOp .isPresent ()) {
336
- return ResultEntity .notFound ();
336
+ return ServiceResultEntity .notFound ();
337
337
}
338
338
339
339
HouseTagEntity houseTag = this .houseTagRepository .findByNameAndHouseId (tag , houseId );
340
340
if (houseTag != null ) {
341
- return new ResultEntity (false , "标签已存在" );
341
+ return new ServiceResultEntity (false , "标签已存在" );
342
342
}
343
343
this .houseTagRepository .save (new HouseTagEntity (houseId , tag ));
344
- return ResultEntity .success ();
344
+ return ServiceResultEntity .success ();
345
345
}
346
346
347
347
@ Override
348
348
@ Transactional
349
- public ResultEntity removeTag (Long houseId , String tag ) {
349
+ public ServiceResultEntity removeTag (Long houseId , String tag ) {
350
350
Optional <HouseEntity > houseOp = this .houseRepository .findById (houseId );
351
351
if (!houseOp .isPresent ()) {
352
- return ResultEntity .notFound ();
352
+ return ServiceResultEntity .notFound ();
353
353
}
354
354
355
355
HouseTagEntity houseTag = this .houseTagRepository .findByNameAndHouseId (tag , houseId );
356
356
if (houseTag == null ) {
357
- return new ResultEntity (false , "标签不存在" );
357
+ return new ServiceResultEntity (false , "标签不存在" );
358
358
}
359
359
360
360
this .houseTagRepository .deleteById (houseTag .getId ());
361
- return ResultEntity .success ();
361
+ return ServiceResultEntity .success ();
362
362
}
363
363
364
364
365
365
@ Override
366
366
@ Transactional
367
- public ResultEntity updateStatus (Long id , int status ) {
367
+ public ServiceResultEntity updateStatus (Long id , int status ) {
368
368
Optional <HouseEntity > houseOp = this .houseRepository .findById (id );
369
369
if (!houseOp .isPresent ()) {
370
- return ResultEntity .notFound ();
370
+ return ServiceResultEntity .notFound ();
371
371
}
372
372
HouseEntity house = houseOp .get ();
373
373
if (house .getStatus () == status ) {
374
- return new ResultEntity (false , "状态没有发生变化" );
374
+ return new ServiceResultEntity (false , "状态没有发生变化" );
375
375
}
376
376
if (house .getStatus () == HouseStatus .RENTED .getValue ()) {
377
- return new ResultEntity (false , "已出租的房源不允许修改状态" );
377
+ return new ServiceResultEntity (false , "已出租的房源不允许修改状态" );
378
378
}
379
379
if (house .getStatus () == HouseStatus .DELETED .getValue ()) {
380
- return new ResultEntity (false , "已删除的资源不允许操作" );
380
+ return new ServiceResultEntity (false , "已删除的资源不允许操作" );
381
381
}
382
382
this .houseRepository .updateStatus (id , status );
383
383
@@ -387,23 +387,23 @@ public ResultEntity updateStatus(Long id, int status) {
387
387
} else {
388
388
searchService .remove (id );
389
389
}
390
- return ResultEntity .success ();
390
+ return ServiceResultEntity .success ();
391
391
}
392
392
393
393
@ Override
394
- public MultiResultEntity <HouseDTO > query (RentSearchParam rentSearch ) {
394
+ public ServiceMultiResultEntity <HouseDTO > query (RentSearchParam rentSearch ) {
395
395
if (rentSearch .getKeywords () != null && !rentSearch .getKeywords ().isEmpty ()) {
396
- MultiResultEntity <Long > multiResult = this .searchService .query (rentSearch );
396
+ ServiceMultiResultEntity <Long > multiResult = this .searchService .query (rentSearch );
397
397
if (multiResult .getTotal () == 0 ) {
398
- return new MultiResultEntity <>(0 , Lists .newArrayList ());
398
+ return new ServiceMultiResultEntity <>(0 , Lists .newArrayList ());
399
399
}
400
- return new MultiResultEntity <>(multiResult .getTotal (), wrapperHouseResult (multiResult .getResult ()));
400
+ return new ServiceMultiResultEntity <>(multiResult .getTotal (), wrapperHouseResult (multiResult .getResult ()));
401
401
}
402
402
// 简单查询
403
403
return simpleQuery (rentSearch );
404
404
}
405
405
406
- private MultiResultEntity <HouseDTO > simpleQuery (RentSearchParam rentSearch ) {
406
+ private ServiceMultiResultEntity <HouseDTO > simpleQuery (RentSearchParam rentSearch ) {
407
407
Sort sort = HouseSort .generateSort (rentSearch .getOrderBy (), rentSearch .getOrderDirection ());
408
408
int page = rentSearch .getStart () / rentSearch .getSize ();
409
409
Pageable pageable = PageRequest .of (page , rentSearch .getSize (), sort );
@@ -440,7 +440,7 @@ private MultiResultEntity<HouseDTO> simpleQuery(RentSearchParam rentSearch) {
440
440
List <Long > houseIds = Lists .newArrayList ();
441
441
houses .forEach (h -> houseIds .add (h .getId ()));
442
442
List <HouseDTO > houseDTOS = wrapperHouseResult (houseIds );
443
- return new MultiResultEntity <>(houses .getTotalElements (), houseDTOS );
443
+ return new ServiceMultiResultEntity <>(houses .getTotalElements (), houseDTOS );
444
444
}
445
445
446
446
/**
@@ -483,25 +483,25 @@ private void wrapperHouseList(List<Long> houseIds, Map<Long, HouseDTO> idToHouse
483
483
484
484
485
485
@ Override
486
- public MultiResultEntity <HouseDTO > wholeMapQuery (MapSearchEntity mapSearch ) {
487
- MultiResultEntity <Long > serviceResult = searchService .mapQuery (mapSearch .getCityEnName (), mapSearch .getOrderBy (), mapSearch .getOrderDirection (), mapSearch .getStart (), mapSearch .getSize ());
486
+ public ServiceMultiResultEntity <HouseDTO > wholeMapQuery (MapSearchEntity mapSearch ) {
487
+ ServiceMultiResultEntity <Long > serviceResult = searchService .mapQuery (mapSearch .getCityEnName (), mapSearch .getOrderBy (), mapSearch .getOrderDirection (), mapSearch .getStart (), mapSearch .getSize ());
488
488
489
489
if (serviceResult .getTotal () == 0 ) {
490
- return new MultiResultEntity <>(0 , Lists .newArrayList ());
490
+ return new ServiceMultiResultEntity <>(0 , Lists .newArrayList ());
491
491
}
492
492
List <HouseDTO > houses = wrapperHouseResult (serviceResult .getResult ());
493
- return new MultiResultEntity <>(serviceResult .getTotal (), houses );
493
+ return new ServiceMultiResultEntity <>(serviceResult .getTotal (), houses );
494
494
}
495
495
496
496
@ Override
497
- public MultiResultEntity <HouseDTO > boundMapQuery (MapSearchEntity mapSearch ) {
498
- MultiResultEntity <Long > serviceResult = searchService .mapQuery (mapSearch );
497
+ public ServiceMultiResultEntity <HouseDTO > boundMapQuery (MapSearchEntity mapSearch ) {
498
+ ServiceMultiResultEntity <Long > serviceResult = searchService .mapQuery (mapSearch );
499
499
if (serviceResult .getTotal () == 0 ) {
500
- return new MultiResultEntity <>(0 , Lists .newArrayList ());
500
+ return new ServiceMultiResultEntity <>(0 , Lists .newArrayList ());
501
501
}
502
502
503
503
List <HouseDTO > houses = wrapperHouseResult (serviceResult .getResult ());
504
- return new MultiResultEntity <>(serviceResult .getTotal (), houses );
504
+ return new ServiceMultiResultEntity <>(serviceResult .getTotal (), houses );
505
505
}
506
506
507
507
}
0 commit comments