doum
2025-12-12 89029e9ade03f3139c6afcd6bac48d9a668875f3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
package com.doumee.service.business.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.config.listener.event.VisitEvent;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.LabelsMapper;
import com.doumee.dao.business.MemberMapper;
import com.doumee.dao.business.ShopJoinMapper;
import com.doumee.dao.business.ShopMapper;
import com.doumee.dao.business.join.ProductLabelJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.business.model.Labels;
import com.doumee.dao.business.model.Shop;
import com.doumee.dao.business.model.ShopComment;
import com.doumee.dao.business.model.ShopScan;
import com.doumee.dao.system.SystemUserMapper;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.dao.web.dto.CouponDTO;
import com.doumee.dao.web.dto.MemberDTO;
import com.doumee.dao.web.dto.MultiFileDTO;
import com.doumee.dao.web.dto.ResetSystemUserPwdDTO;
import com.doumee.dao.web.dto.shop.*;
import com.doumee.service.business.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.shiro.SecurityUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 店铺基本信息表Service实现
 * @author 江蹄蹄
 * @date 2023/03/21 15:48
 */
@Service
public class ShopServiceImpl implements ShopService {
 
    @Autowired
    private ShopMapper shopMapper;
 
    @Autowired
    private ShopCommentService shopCommentService;
 
    @Autowired
    private ProductLabelService productLabelService;
 
    @Autowired
    private ShopMenuService shopMenuService;
 
    @Resource
    private ApplicationEventPublisher applicationEventPublisher;
 
    @Autowired
    public CouponService couponService;
 
 
    @Autowired
    private ShopJoinMapper shopJoinMapper;
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    @Autowired
    private MemberMapper memberMapper;
 
    @Autowired
    private SystemUserMapper systemUserMapper;
 
    @Autowired
    private ProductLabelJoinMapper productLabelJoinMapper;
 
    @Autowired
    private ShopFollowService shopFollowService;
 
    @Autowired
    private ShopScanService shopScanService;
 
    @Autowired
    private MemberCouponService memberCouponService;
 
    @Autowired
    private ShopNewsService shopNewsService;
    @Autowired
    private LabelsMapper labelsMapper;
 
    @Autowired
    private MultifileService multifileService;
 
 
    @Override
    public Integer create(Shop shop) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        isCreateParamValid(shop,user);
        shop.setCreator(user.getId());
        shop.setCreateDate(new Date());
        shop.setEditor(user.getId());
        shop.setEditDate(shop.getCreateDate());
        shop.setIsdeleted(Constants.ZERO);
        shop.setStatus(Constants.ZERO);
        shop.setIsrec(Constants.ONE);
        shop.setOrigin(Constants.ONE);
        shop.setSaleType(Constants.formatIntegerNum(shop.getSaleType()));
        String salt = RandomStringUtils.randomAlphabetic(6);
 
        shop.setPassword(shop.getCode()+"@123456");
        // 生成密码
        shop.setPassword(Utils.Secure.encryptPassword(shop.getPassword(), salt));
        shop.setSalt(salt);
        shopMapper.insert(shop);
        return shop.getId();
    }
 
    public void isCreateParamValid(Shop shop , LoginUserInfo user){
        try {
            String[] ss = shop.getLocationInfo().split(",");
            shop.setLatitude(BigDecimal.valueOf(Double.parseDouble(ss[0])));
            shop.setLongitude(BigDecimal.valueOf(Double.parseDouble(ss[1])));
        }catch (Exception e){
        }
        if(StringUtils.isBlank(shop.getUsername())
                ||  StringUtils.isBlank(shop.getPhone())
                ||  StringUtils.isBlank(shop.getBusinessImg())
                ||  StringUtils.isBlank(shop.getStartTime())
                ||   shop.getLatitude()==null
                ||   shop.getLongitude()==null
                ||   shop.getBigAreaId()==null
                ||   shop.getAreaId()==null
                ||  StringUtils.isBlank(shop.getRealname())
                ||  StringUtils.isBlank(shop.getName())
                ||  StringUtils.isBlank(shop.getCode())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        if(AreasServiceImpl.getAddressByAreaId(shop.getAreaId()) ==null){
 
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请选择正确的省市区信息~");
        }
        if(labelsMapper.selectById(shop.getBigAreaId()) ==null){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请选择正确的区域信息~");
        }
        if(shopMapper.selectCount(new QueryWrapper<Shop>().lambda()
                .eq(Shop::getName,shop.getName())
                .ne(shop.getId()!=null,Shop::getId,shop.getId())
                .eq(Shop::getIsdeleted,Constants.ZERO))>0){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"经销商名称重复,请返回修改~");
        }
        if(shopMapper.selectCount(new QueryWrapper<Shop>().lambda()
                .eq(Shop::getCode,shop.getCode())
                .ne(shop.getId()!=null,Shop::getId,shop.getId())
                .eq(Shop::getIsdeleted,Constants.ZERO))>0){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"门店ID重复,请返回修改~");
        }
        if(shopMapper.selectCount(new QueryWrapper<Shop>().lambda()
                .eq(Shop::getUsername,shop.getUsername())
                .ne(shop.getId()!=null,Shop::getId,shop.getId())
                .eq(Shop::getIsdeleted,Constants.ZERO))>0){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"登录账号重复,请返回修改~");
        }
    }
 
    @Override
    public void deleteById(Integer id) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        Shop shop =new Shop();
        shop.setId(id);
        shop.setEditor(user.getId());
        shop.setEditDate(new Date());
        shop.setIsdeleted(Constants.ONE);
        shopMapper.updateById(shop);
    }
 
    @Override
    public void delete(Shop shop) {
        UpdateWrapper<Shop> deleteWrapper = new UpdateWrapper<>(shop);
        shopMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        shopMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(Shop shop) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(shop.getId()==null ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), ResponseStatus.BAD_REQUEST.getMessage());
        }
        isCreateParamValid(shop,user);
        shop.setEditor(user.getId());
        shop.setEditDate(new Date());
        shopMapper.updateById(shop);
    }
 
 
    @Override
    public void updateIsRecById(Shop shop) {
 
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        shop.setEditor(user.getId());
        shop.setEditDate(new Date());
        shopMapper.updateById(shop);
    }
 
 
    @Override
    public void updateByIdInBatch(List<Shop> shops) {
        if (CollectionUtils.isEmpty(shops)) {
            return;
        }
        for (Shop shop: shops) {
            this.updateById(shop);
        }
    }
 
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    @Override
    public void update(ShopDTO shopDTO, Integer memberId) {
//        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<SystemUser> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(SystemUser::getMemberId,memberId);
        SystemUser user = systemUserMapper.selectById(wrapper);
        Shop shop = new Shop();
        shop.setId(shopDTO.getId());
        shop.setEditor(user.getId());
        shop.setEditDate(new Date());
        shop.setImgurl(shopDTO.getImgurl());
        shop.setName(shopDTO.getName());
        shop.setAddr(shopDTO.getAddr());
        shop.setStartTime(shopDTO.getStartTime());
        shop.setEndTime(shopDTO.getEndTime());
        shop.setBrandStory(shopDTO.getBrandStory());
        if (!CollectionUtils.isEmpty(shopDTO.getMultiFileDTOS())){
 
            multifileService.refreshObjMultiFile(shopDTO.getId(),Constants.MultiFile.SHOP_PICTURE.getKey(),shopDTO.getMultiFileDTOS());
        }
        if (!CollectionUtils.isEmpty(shopDTO.getLabels())){
            shopDTO.getLabels().forEach(s->{
                ProductLabel productLabel = new ProductLabel();
                productLabel.setCreator(user.getId());
                productLabel.setCreateDate(new Date());
                productLabel.setEditor(user.getId());
                productLabel.setEditDate(new Date());
                productLabel.setIsdeleted(Constants.ZERO);
                productLabel.setLabelId(s);
                productLabel.setShopId(shopDTO.getId());
                productLabelService.create(productLabel);
            });
        }
    }
 
    @Override
    public Shop findById(Integer id) {
        MPJLambdaWrapper<Shop> queryWrapper = new MPJLambdaWrapper<>();
 
        queryWrapper.selectAll(Shop.class);
 
        queryWrapper.eq(Shop::getId,id);
        queryWrapper.select("(select AVG(SCORE) from shop_comment where ISDELETED=0 and OBJ_ID=t.id) as score");//门店评分
        /** ----------------start店铺访问数据----------------*/
        queryWrapper.select("(select count(id) from shop_scan where ISDELETED=0 and SHOP_ID=t.id) as shopTotalVisits");//主页总访问量
        queryWrapper.select("(select count(id) from shop_scan where ISDELETED=0 and SHOP_ID=t.id and to_days(CREATE_DATE)=to_days(now()) ) as shopNowVisits");//今日访问量
        queryWrapper.select("(select count(id) from shop_scan where ISDELETED=0 and SHOP_ID=t.id and to_days(CREATE_DATE)=to_days(DATE_SUB(CURDATE(), INTERVAL 1 DAY)) ) as shopYesterdayVisits");//昨日日访问量
        queryWrapper.select("(select count(s.MEMBER_ID) from (select MEMBER_ID,SHOP_ID from shop_scan where ISDELETED=0   group by MEMBER_ID) as s where   s.SHOP_ID = t.id) as shopMemberVisits");//访问总用户数
        /** ----------------end店铺访问数据----------------*/
        /** ----------------start店铺互动数据----------------*/
        queryWrapper.select("(select count(id) from shop_follow where ISDELETED=0 and OBJ_ID=t.id and OBJ_TYPE=0) as shopFollower");//粉丝数
        queryWrapper.select("(select count(id) from shop_menu where ISDELETED=0 and SHOP_ID=t.id ) as shopMenu");//菜品数
        queryWrapper.select("(select count(id) from shop_comment where ISDELETED=0 and OBJ_ID=t.id ) as shopComment");//评论数
        queryWrapper.select("(select count(id) from shop_news where ISDELETED=0 and SHOP_ID=t.id ) as shopNews");//新鲜事
        /** ----------------end店铺互动数据----------------*/
        /** ----------------start优惠券数据----------------*/
        queryWrapper.select("(select count(id) from coupon where ISDELETED=0 and SHOP_ID=t.id and type=0) as couponCount");//优惠券发放总数(张)
        queryWrapper.select("(select count(id) from member_coupon where ISDELETED=0 and SHOP_ID=t.id and type=0) as couponDrawCount");//优惠券领取总数(张)
        queryWrapper.select("(select count(id) from member_coupon where ISDELETED=0 and SHOP_ID=t.id and type=0 and STATUS=1 ) as couponUserComment");//优惠券使用总数(张)
        queryWrapper.select("(select sum(LIMIT_PRICE) from member_coupon where ISDELETED=0 and SHOP_ID=t.id and type=0 and STATUS=1 ) as couponUserMoney");//优惠券使用金额(元)
        /** ----------------end店铺优惠券数据----------------*/
 
       Shop shop= shopJoinMapper.selectJoinOne(Shop.class,queryWrapper);
        String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.SHOP_FILE).getCode();
        if(Objects.nonNull(shop)&&StringUtils.isNotBlank(shop.getImgurl())){
            shop.setImgFullUrl(path+shop.getImgurl());
        }
        shop.setAreas(AreasServiceImpl.getAddressByAreaId(shop.getAreaId()));
        if(shop.getLatitude()!=null && shop.getLongitude()!=null){
            shop.setLocationInfo(shop.getLatitude().doubleValue()+","+shop.getLongitude().doubleValue());
        }
        MPJLambdaWrapper<ProductLabel> queryproduct = new MPJLambdaWrapper<>();
        queryproduct.selectAs(Labels::getName,ProductLabel::getLablesName);
        queryproduct.eq(ProductLabel::getIsdeleted,Constants.ZERO);
        queryproduct.eq(ProductLabel::getShopId,shop.getId());
        queryproduct.leftJoin(Labels.class, Labels::getId,ProductLabel::getLabelId);
        List<ProductLabel> list=productLabelJoinMapper.selectJoinList(ProductLabel.class,queryproduct);
        shop.setProductList(list);
        return shop;
    }
 
    @Override
    public Shop findOne(Shop shop) {
        QueryWrapper<Shop> wrapper = new QueryWrapper<>(shop);
        return shopMapper.selectOne(wrapper);
    }
 
    @Override
    public List<Shop> findList(Shop shop) {
        QueryWrapper<Shop> wrapper = new QueryWrapper<>(shop);
        return shopMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<Shop> findPage(PageWrap<Shop> pageWrap) {
        IPage<Shop> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<Shop> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
 
        queryWrapper.selectAll(Shop.class);
        queryWrapper.selectAs(Labels::getName,Shop::getBigAreaName);
        queryWrapper.selectAs(Member::getNickname,Shop::getNickName);
        queryWrapper.selectAs(Member::getImgurl,Shop::getMemberImgurl);
        queryWrapper.selectAs(Member::getPhone,Shop::getMemberPhone);
 
        queryWrapper.leftJoin(Member.class,Member::getId,Shop::getMemberId);
        queryWrapper.leftJoin(Labels.class,Labels::getId,Shop::getBigAreaId);
 
        queryWrapper.eq(Shop::getIsdeleted, Constants.ZERO);
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCode()) ,Shop::getCode,pageWrap.getModel().getCode());
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getUsername()) ,Shop::getName,pageWrap.getModel().getUsername());
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()) ,Shop::getName,pageWrap.getModel().getName());
        queryWrapper.eq(pageWrap.getModel().getSaleType()!=null, Shop::getSaleType, pageWrap.getModel().getSaleType());
        queryWrapper.eq(pageWrap.getModel().getStatus()!=null, Shop::getStatus, pageWrap.getModel().getStatus());
        queryWrapper.eq(pageWrap.getModel().getIsrec()!=null, Shop::getIsrec, pageWrap.getModel().getIsrec());
        queryWrapper.orderByDesc(Shop::getCreateDate);
        IPage<Shop> result = shopJoinMapper.selectJoinPage(page, Shop.class, queryWrapper);
        String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.SHOP_FILE).getCode();
        for(Shop model:result.getRecords()){
            model.setImgFullUrl(path);
            model.setAreas( AreasServiceImpl.getAddressByAreaId(model.getAreaId()));
            if(model.getLatitude()!=null && model.getLongitude()!=null){
                model.setLocationInfo(model.getLatitude().doubleValue()+","+model.getLongitude().doubleValue());
            }
 
        }
        return PageData.from(result );
    }
 
    @Override
    public List<Shop> findAll(PageWrap<Shop> pageWrap) {
 
        MPJLambdaWrapper<Shop> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
 
        queryWrapper.selectAll(Shop.class);
        queryWrapper.eq(Shop::getIsdeleted, Constants.ZERO);
 
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()), Shop::getName, pageWrap.getModel().getName());
        queryWrapper.orderByDesc(Shop::getCreateDate);
        List<Shop> result = shopJoinMapper.selectList(queryWrapper);
 
        return result;
    }
 
 
    @Override
    public long count(Shop shop) {
        QueryWrapper<Shop> wrapper = new QueryWrapper<>(shop);
        return shopMapper.selectCount(wrapper);
    }
 
    @Override
    public ShopSimpleDTO getShopSimpleDTO(Integer shopId) {
        Shop queryShop = new Shop();
        queryShop.setId(shopId);
        QueryWrapper<Shop> queryWapper = new QueryWrapper<>(queryShop);
        queryWapper.lambda().eq(Shop::getIsdeleted, Constants.ZERO);
        queryWapper.select("*,(select avg(score) from shop_comment b where b.OBJ_ID = shop.id and b.isdeleted=0) as starNum");
        queryWapper.lambda().last(" limit 1");
        Shop shop = shopMapper.selectOne(queryWapper);
        if(shop !=null){
           /* ShopComment avg = shopCommentService.findAvg(shopId);
 
            if(avg!=null){
                shopSimpleDTO.setStarNum(avg.getScore());
            }*/
            ShopSimpleDTO shopSimpleDTO = new ShopSimpleDTO();
            BeanUtils.copyProperties(shop,shopSimpleDTO);
            return shopSimpleDTO;
        }
        return  null;
    }
 
    @Override
    public List<ShopSimpleDTO> getShopSimpleDTOList(List<Integer> shopIds) {
 
        QueryWrapper<Shop> wrapper = new QueryWrapper<>();
        wrapper.lambda().in(Shop::getId,shopIds);
 
        List<Shop> shops = shopMapper.selectList(wrapper);
 
        List<ShopComment> avgs = shopCommentService.getAvgs(shopIds);
        final Map<Integer, ShopComment> collect = avgs.stream().collect(Collectors.toMap(ShopComment::getObjId, s -> s));
        final Map<Integer, List<String>> labelsByIds = productLabelService.getLabelsByIds(shopIds);
 
        List<ShopSimpleDTO> shopSimpleList = shops.stream().map(s -> {
            ShopSimpleDTO dto = new ShopSimpleDTO();
            BeanUtils.copyProperties(s, dto);
            ShopComment shopComment = collect.get(s.getId());
            List<String> labels = labelsByIds.get(s.getId());
            dto.setLabels(labels);
            dto.setStarNum(shopComment != null ? shopComment.getScore() : null);
            return dto;
        }).collect(Collectors.toList());
 
 
        return shopSimpleList;
    }
 
    @Override
    public ShopFaceDetailDTO getShopFaceDetailDTO(Integer shopId,Integer memberId) {
//        LoginUserInfo info = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        Shop queryShop = new Shop();
        queryShop.setId(shopId);
        Shop shop = shopMapper.selectOne(new QueryWrapper<>(queryShop)
                .lambda().eq(Shop::getIsdeleted, Constants.ZERO));
 
        shop = Optional.ofNullable(shop).orElseThrow(()->new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,商家信息不存在!"));
 
        ShopFaceDetailDTO dto = new ShopFaceDetailDTO();
 
        Map<Integer, List<MultiFileDTO>> objAllFileUrl = multifileService.getOBJAllFileUrl(shopId, Constants.MultiFile.SHOP_PICTURE.getKey(), Constants.ZERO,Constants.SHOP_FILE);
        //附件信息
        dto.setBannerImgUrlList((List<MultiFileDTO>) MapUtils.getObject(objAllFileUrl,Constants.MultiFile.SHOP_PICTURE.getKey()));
        BeanUtils.copyProperties(shop,dto);
 
        CouponDTO couponDTO = couponService.findCouponDTO(shopId, memberId);
        dto.setCouponDTO(couponDTO);
 
        List<Labels> labels = productLabelService.getLabelsById(shopId);
        labels = Optional.ofNullable(labels).orElse(new ArrayList<>());
        dto.setLabels(labels.stream().map(s->s.getName()).collect(Collectors.toList()));
        List<ShopMenuDTO> shopMenuDTO = shopMenuService.findShopMenuDTO(shopId);
        dto.setShopMenuDTOList(shopMenuDTO);
        //访问操作
        VisitEvent<Shop> shopVisitEvent = new VisitEvent<>(this,shop);
        applicationEventPublisher.publishEvent(shopVisitEvent);
        return dto;
    }
 
 
    @Override
    public MemberDTO getShopMemberDTO(Integer shopId, Integer memberId) {
//        LoginUserInfo info = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        MemberDTO memberDTO = shopFollowService.getMemberDTO(shopId, memberId,Constants.ZERO);
        return memberDTO;
    }
 
    @Override
    public PageData<ShopSimpleDTO> getShopSimpleDTOList(PageWrap<ShopSimpleDTO> pageWrap) {
 
        IPage<Shop> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        Utils.MP.blankToNull(pageWrap.getModel());
        QueryWrapper<Shop> wrapper = new QueryWrapper<>();
        //左上
        Position upperLeft = pageWrap.getModel().getUpperLeft();
        //右下
        Position lowRight  = pageWrap.getModel().getLowRight();
        wrapper.lambda()
                .like(Shop::getName,pageWrap.getModel().getName())
                .between((Objects.nonNull(upperLeft.getLongitude()) && Objects.nonNull(lowRight.getLongitude())),
                        Shop::getLongitude,
                        upperLeft.getLongitude(),
                        lowRight.getLongitude())
                .between((Objects.nonNull(upperLeft.getLatitude()) && Objects.nonNull(lowRight.getLatitude())),
                        Shop::getLongitude,
                        upperLeft.getLatitude(),
                        lowRight.getLatitude());
        IPage<Shop> shopIPage = shopMapper.selectPage(page, wrapper);
 
        if (CollectionUtils.isEmpty(shopIPage.getRecords())){
            return PageData.from(new Page<>());
        }
 
        List<Integer> shopIds = shopIPage.getRecords().stream().map(s -> s.getId()).collect(Collectors.toList());
 
        List<ShopComment> avgs = shopCommentService.getAvgs(shopIds);
        final Map<Integer, ShopComment> collect = avgs.stream().collect(Collectors.toMap(ShopComment::getObjId, s -> s));
        final Map<Integer, List<String>> labelsByIds = productLabelService.getLabelsByIds(shopIds);
        List<ShopSimpleDTO> shopSimpleList = shopIPage.getRecords().stream().map(s -> {
            ShopSimpleDTO dto = new ShopSimpleDTO();
            BeanUtils.copyProperties(s, dto);
            ShopComment shopComment = collect.get(s.getId());
            List<String> labels = labelsByIds.get(s.getId());
            dto.setLabels(labels);
            dto.setStarNum(shopComment != null ? shopComment.getScore() : new BigDecimal("0"));
            return dto;
        }).collect(Collectors.toList());
 
        IPage<ShopSimpleDTO> shopSimpleDTOIPage = new Page<>();
        shopSimpleDTOIPage.setPages(shopIPage.getPages());
        shopSimpleDTOIPage.setRecords(shopSimpleList);
        shopSimpleDTOIPage.setTotal(shopIPage.getTotal());
        shopSimpleDTOIPage.setSize(shopIPage.getSize());
        shopSimpleDTOIPage.setCurrent(shopIPage.getCurrent());
 
        return PageData.from(shopSimpleDTOIPage);
    }
 
    @Override
    public ShopDataStatisticsDTO getShopDataStatisticsDTO(Integer shopId) {
 
        MemberCoupon memberCoupon = new MemberCoupon();
        memberCoupon.setShopId(shopId);
        memberCoupon.setType(Constants.ZERO);
        memberCoupon.setStatus(Constants.ONE);
        long shopCouponUseCount = memberCouponService.count(memberCoupon);
 
        ShopFollow shopFollow = new ShopFollow();
        shopFollow.setObjId(shopId);
        shopFollow.setObjType(Constants.ZERO);
        long shopFansCount = shopFollowService.count(shopFollow);
 
        ShopNews shopNews = new ShopNews();
        shopNews.setShopId(shopId);
        long shopNewCount = shopNewsService.count(shopNews);
        ShopDataStatisticsDTO shopDataStatisticsDTO = new ShopDataStatisticsDTO();
        shopDataStatisticsDTO.setShopCouponUseCount(shopCouponUseCount)
                .setShopFansCount(shopFansCount).setShopNewCount(shopNewCount);
        return shopDataStatisticsDTO;
    }
 
    @Override
    public void visitOperation(Object o) {
//        LoginUserInfo info = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        Shop shop = (Shop) o;
        UpdateWrapper<Shop> wrapper = new UpdateWrapper<>();
        wrapper.lambda().set(Shop::getLooknum, Objects.isNull(shop.getLooknum()) ? 1 : shop.getLooknum()+1);
        shopMapper.update(null,wrapper);
        ShopScan shopScan = new ShopScan();
//        shopScan.setCreator(info.getId());
        shopScan.setCreateDate(new Date());
//        shopScan.setEditor(info.getId());
        shopScan.setEditDate(new Date());
        shopScan.setShopId(shop.getId());
        shopScan.setMemberId(shop.getMemberId());
        shopScanService.create(shopScan);
    }
 
    @Override
    public void resetPwd(Shop dto) {
        // 查询用户
        Shop shop = findById(dto.getId());
        if (shop == null) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        // 修改密码
        Shop updateUserDto = new Shop();
        updateUserDto.setId(dto.getId());
        updateUserDto.setPassword(Utils.Secure.encryptPassword( shop.getCode()+"@123456", shop.getSalt()));
        shopMapper.updateById(updateUserDto);
    }
}