jiangping
2024-07-09 224211c30a69a9f44af2ce9613073b29a8b6195c
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
package com.doumee.service.business.impl;
 
import com.doumee.core.annotation.excel.ExcelImporter;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
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.admin.request.FcodeImport;
import com.doumee.dao.admin.request.ShopImport;
import com.doumee.dao.admin.request.UpdateShopSortDTO;
import com.doumee.dao.business.ShopMapper;
import com.doumee.dao.business.join.ShopJoinMapper;
import com.doumee.dao.business.model.Member;
import com.doumee.dao.business.model.Shop;
import com.doumee.dao.business.vo.ShopTree;
import com.doumee.dao.business.vo.ShopTreeVo;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.ShopService;
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 com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 志邦组织信息表Service实现
 * @author 江蹄蹄
 * @date 2024/07/04 14:40
 */
@Service
public class ShopServiceImpl implements ShopService {
 
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private ShopJoinMapper shopMapper;
 
    @Override
    public Long create(Shop shop) {
        shopMapper.insert(shop);
        return shop.getId();
    }
 
    @Override
    public void deleteById(Long id) {
        shopMapper.deleteById(id);
    }
 
    @Override
    public void delete(Shop shop) {
        UpdateWrapper<Shop> deleteWrapper = new UpdateWrapper<>(shop);
        shopMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        shopMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(Shop shop) {
        shopMapper.updateById(shop);
    }
 
    @Override
    public void updateByIdInBatch(List<Shop> shops) {
        if (CollectionUtils.isEmpty(shops)) {
            return;
        }
        for (Shop shop: shops) {
            this.updateById(shop);
        }
    }
 
    @Override
    public Shop findById(Long id) {
        return shopMapper.selectById(id);
    }
 
    @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 List<Shop> listByParent(String piamId) {
        QueryWrapper<Shop> wrapper = new QueryWrapper<>();
        wrapper .select("shop.*,(select count(b.id) from shop b where b.isdeleted=0 and b.parent_iam_id = shop.org_id) as childNum")
                .lambda()
                .eq(StringUtils.isNotBlank(piamId),Shop::getParentIamId,piamId)
                .isNull(StringUtils.isBlank(piamId),Shop::getParentIamId)
//                .eq(Shop::getIsdeleted,Constants.ZERO)
                .orderByAsc(Shop::getOrderNum);
        List<Shop> list = shopMapper.selectList(wrapper);
        if(list!=null){
            for (Shop shop :list){
                shop.setIsLeaf(shop.getChildNum()<=0);
                shop.setHasChildren(shop.getChildNum()>0);
//                shop.setChildList(shopMapper.selectList(new QueryWrapper<Shop>().lambda().eq(Shop::getParentIamId,shop.getOrgId())));
            }
        }
        return  list;
 
    }
 
    @Override
    public PageData<Shop> findPage(PageWrap<Shop> pageWrap) {
        IPage<Shop> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<Shop> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Shop.class);
        queryWrapper.leftJoin(" shop t1 on t1.org_id = t.parent_iam_id");
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.eq(Shop::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getCreator() != null) {
            queryWrapper.eq(Shop::getCreator, pageWrap.getModel().getCreator());
        }
        if (pageWrap.getModel().getCreateDate() != null) {
            queryWrapper.ge(Shop::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
            queryWrapper.le(Shop::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
        }
        if (pageWrap.getModel().getEditor() != null) {
            queryWrapper.eq(Shop::getEditor, pageWrap.getModel().getEditor());
        }
        if (pageWrap.getModel().getEditDate() != null) {
            queryWrapper.ge(Shop::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
            queryWrapper.le(Shop::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
        }
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.eq(Shop::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.eq(Shop::getRemark, pageWrap.getModel().getRemark());
        }
        if (pageWrap.getModel().getOrgId() != null) {
            queryWrapper.eq(Shop::getOrgId, pageWrap.getModel().getOrgId());
        }
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()),Shop::getName, pageWrap.getModel().getName());
        if (pageWrap.getModel().getOrgOldId() != null) {
            queryWrapper.eq(Shop::getOrgOldId, pageWrap.getModel().getOrgOldId());
        }
        if (pageWrap.getModel().getParentId() != null) {
            queryWrapper.eq(Shop::getParentId, pageWrap.getModel().getParentId());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.eq(Shop::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getOrderNum() != null) {
            queryWrapper.eq(Shop::getOrderNum, pageWrap.getModel().getOrderNum());
        }
        if (pageWrap.getModel().getSourceCode() != null) {
            queryWrapper.eq(Shop::getSourceCode, pageWrap.getModel().getSourceCode());
        }
        if (pageWrap.getModel().getCode() != null) {
            queryWrapper.eq(Shop::getCode, pageWrap.getModel().getCode());
        }
        if (pageWrap.getModel().getType() != null) {
            queryWrapper.eq(Shop::getType, pageWrap.getModel().getType());
        }
        if (pageWrap.getModel().getAttribute() != null) {
            queryWrapper.eq(Shop::getAttribute, pageWrap.getModel().getAttribute());
        }
        if (pageWrap.getModel().getWeixinId() != null) {
            queryWrapper.eq(Shop::getWeixinId, pageWrap.getModel().getWeixinId());
        }
        if (pageWrap.getModel().getDingdingId() != null) {
            queryWrapper.eq(Shop::getDingdingId, pageWrap.getModel().getDingdingId());
        }
        if (pageWrap.getModel().getSyncDate() != null) {
            queryWrapper.ge(Shop::getSyncDate, Utils.Date.getStart(pageWrap.getModel().getSyncDate()));
            queryWrapper.le(Shop::getSyncDate, Utils.Date.getEnd(pageWrap.getModel().getSyncDate()));
        }
        if (pageWrap.getModel().getSyncInfo() != null) {
            queryWrapper.eq(Shop::getSyncInfo, pageWrap.getModel().getSyncInfo());
        }
        if (pageWrap.getModel().getFcode() != null) {
            queryWrapper.eq(Shop::getFcode, pageWrap.getModel().getFcode());
        }
        if (pageWrap.getModel().getScode() != null) {
            queryWrapper.eq(Shop::getScode, pageWrap.getModel().getScode());
        }
        if (pageWrap.getModel().getZcode() != null) {
            queryWrapper.eq(Shop::getZcode, pageWrap.getModel().getZcode());
        }
        if (pageWrap.getModel().getGlCode() != null) {
            queryWrapper.eq(Shop::getGlCode, pageWrap.getModel().getGlCode());
        }
        if (pageWrap.getModel().getGlName() != null) {
            queryWrapper.eq(Shop::getGlName, pageWrap.getModel().getGlName());
        }
            queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCountry()),Shop::getCountry, pageWrap.getModel().getCountry());
        if (pageWrap.getModel().getProvinceCode() != null) {
            queryWrapper.eq(Shop::getProvinceCode, pageWrap.getModel().getProvinceCode());
        }
            queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getProvinceName()),Shop::getProvinceName, pageWrap.getModel().getProvinceName());
        if (pageWrap.getModel().getCityCode() != null) {
            queryWrapper.eq(Shop::getCityCode, pageWrap.getModel().getCityCode());
        }
            queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCityName()),Shop::getCityName, pageWrap.getModel().getCityName());
        if (pageWrap.getModel().getAreaCode() != null) {
            queryWrapper.eq(Shop::getAreaCode, pageWrap.getModel().getAreaCode());
        }
            queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getAreaName()),Shop::getAreaName, pageWrap.getModel().getAreaName());
        if (pageWrap.getModel().getUnitCode() != null) {
            queryWrapper.eq(Shop::getUnitCode, pageWrap.getModel().getUnitCode());
        }
        if (pageWrap.getModel().getSecondType() != null) {
            queryWrapper.eq(Shop::getSecondType, pageWrap.getModel().getSecondType());
        }
        queryWrapper.apply(StringUtils.isNotBlank(pageWrap.getModel().getParentName()),
                    "(t1.name like '%"+pageWrap.getModel().getParentName()+"%' or t1.code like '%"+pageWrap.getModel().getParentName()+"%' )" );
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(shopMapper.selectPage(page, queryWrapper));
    }
 
    @Override
    public long count(Shop shop) {
        QueryWrapper<Shop> wrapper = new QueryWrapper<>(shop);
        return shopMapper.selectCount(wrapper);
    }
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public String importFcodeBatch(MultipartFile file){
        Boolean importing = (Boolean) redisTemplate.opsForValue().get(Constants.RedisKeys.IMPORTING_SHOP);
        if(importing!=null && importing){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,已存在导入或者上下级重置任务正在执行中,请稍后再试!");
        }
        redisTemplate.opsForValue().set(Constants.RedisKeys.IMPORTING_SHOP,true);
        try {
            LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
            ExcelImporter ie = null;
            List<FcodeImport> dataList =null;
            try {
                ie = new ExcelImporter(file,0,0);
                dataList = ie.getDataList(FcodeImport.class,null);
            }  catch (Exception e) {
                e.printStackTrace();
            }
            if(dataList == null || dataList.size() ==0){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入数据为空!");
            }
            Date date =new Date();
            List<Shop> updateShops = new ArrayList<>();
            for(int i=0;i<dataList.size();i++){
                FcodeImport model = dataList.get(i);
                if(StringUtils.isBlank(model.getOrgId())  ){
                    continue;
                }
                Shop shop = shopMapper.selectOne(new QueryWrapper<Shop>().lambda().eq(Shop::getOrgId,model.getOrgId()));
                if(shop == null){
                    continue;
                }
                shop.setCountry(model.getCountry());
                shop.setProvinceCode(model.getProvinceCode());
                shop.setProvinceName(model.getProvinceName());
                shop.setCityCode(model.getCityCode());
                shop.setCityName(model.getCityName());
                shop.setTown(model.getTown());
                shop.setEditDate(date);
                shop.setEditor(loginUserInfo.getId());
                shop.setAreaCode(model.getAreaCode());
                shop.setAreaName(model.getAreaName());
                shop.setRegAddr(model.getRegAddr());
                shop.setLegalPhone(model.getLegalPhone());
                shop.setLegalIdcode(model.getLegalIdcode());
                shop.setLegalName(model.getLegalName());
                shop.setTaxRegCode(model.getTaxRegCode());
                shopMapper.updateById(shop);
            }
 
            return "导入成功";
        }catch (BusinessException e){
            throw e;
        }catch (Exception e){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"信息导入失败,请稍后重试");
        }finally {
            redisTemplate.delete(Constants.RedisKeys.IMPORTING_SHOP);
        }
    }
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public String importBatch(MultipartFile file){
        Boolean importing = (Boolean) redisTemplate.opsForValue().get(Constants.RedisKeys.IMPORTING_SHOP);
        if(importing!=null && importing){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,已存在导入或者上下级重置任务正在执行中,请稍后再试!");
        }
        redisTemplate.opsForValue().set(Constants.RedisKeys.IMPORTING_SHOP,true);
        try {
            LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
            ExcelImporter ie = null;
            List<ShopImport> dataList =null;
            try {
                ie = new ExcelImporter(file,1,0);
                dataList = ie.getDataList(ShopImport.class,null);
            }  catch (Exception e) {
                e.printStackTrace();
            }
            if(dataList == null || dataList.size() ==0){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入数据为空!");
            }
            List<Shop> list =  shopMapper.selectJoinList(Shop.class,new MPJLambdaWrapper<Shop>()
                    .selectAll(Shop.class)
            );
            List<Shop> insertShops = new ArrayList<>();
            Date date =new Date();
            List<Shop> updateShops = new ArrayList<>();
            for(int i=0;i<dataList.size();i++){
                ShopImport model = dataList.get(i);
                if(StringUtils.isBlank(model.getName())
                        &&StringUtils.isBlank(model.getCode()) ){
                    continue;
                }
                Shop shop = checkModelParam(model,insertShops,updateShops,i,loginUserInfo,list,date);
            }
            if(insertShops .size() >0){
                int temp = 0;
                while(temp < insertShops.size()){
                    int index;
                    if(temp + 500 <= insertShops.size()){
                        index = temp+500;
                    }else{
                        index = insertShops.size();
                    }
                    shopMapper.insert(insertShops.subList(temp,index));
                    temp = index;
                }
            }
            if(updateShops .size() >0){
                for(Shop s : updateShops){
                    //遍历更新数据
                    shopMapper.updateById(s);
                }
            }
            return "导入成功";
        }catch (BusinessException e){
            throw e;
        }catch (Exception e){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"信息导入失败,请稍后重试");
        }finally {
            redisTemplate.delete(Constants.RedisKeys.IMPORTING_SHOP);
        }
    }
 
 
    private Shop checkModelParam(ShopImport model, List<Shop> newList, List<Shop> updateList, int index, LoginUserInfo loginUserInfo
            , List<Shop> list,Date date) {
        if(StringUtils.isBlank(model.getOrgId())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+(index+3)+"行【组织编码】信息不完整,请检查表格内容!");
        }
        if(StringUtils.isBlank(model.getName())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+(index+3)+"行【组织名称】信息不完整,请检查表格内容!");
        }
        if( Constants.formatIntegerNum(model.getType()) <1 || Constants.formatIntegerNum(model.getType()) >3 ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+(index+3)+"行【组织一级类型】信息不正确,请填写1-5正确的类型值,请检查表格内容!");
        }
        if( model.getSecondType()!=null && (Constants.formatIntegerNum(model.getSecondType()) <1 || Constants.formatIntegerNum(model.getSecondType()) >5) ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+(index+3)+"行【组织二级类型】信息不正确,请填写1-5正确的类型值,请检查表格内容!");
        }
        if( Constants.formatIntegerNum(model.getType()) <1 || Constants.formatIntegerNum(model.getType()) >5 ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+(index+3)+"行【组织类型】信息不正确,请填写1-5正确的类型值,请检查表格内容!");
        }
        if( model.getAttribute() !=null && (Constants.formatIntegerNum(model.getAttribute()) <1 || Constants.formatIntegerNum(model.getAttribute()) >5 )){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+(index+3)+"行【组织属性】信息不正确,请填写1-5正确的属性值,请检查表格内容!");
        }
        Shop shop = getShopByOrgID(model.getOrgId(),list);
        if(shop == null){
            shop = new Shop();
            shop.setCreator(loginUserInfo.getId());
            shop.setCreateDate(date);
            shop.setEditor(loginUserInfo.getId());
            shop.setEditDate(date);
            shop.setOrgId(model.getOrgId());
            shop.setName(model.getName());
            shop.setCode(model.getCode());
            shop.setUnitCode(model.getUnitCode());
            shop.setStatus(model.getStatus());
            if(Constants.equalsInteger(model.getStatus(),Constants.TWO)){
                shop.setIsdeleted(Constants.ONE);
            }else{
                shop.setIsdeleted(Constants.ZERO);
            }
            shop.setType(model.getType());
            shop.setSecondType(model.getSecondType());
            shop.setAttribute(model.getAttribute());
            shop.setParentIamId(model.getParentOrgId());
            newList.add(shop);
        }else {
            shop.setEditor(loginUserInfo.getId());
            shop.setEditDate(date);
            shop.setType(model.getType());
            shop.setSecondType(model.getSecondType());
            shop.setName(model.getName());
            shop.setCode(model.getCode());
            shop.setUnitCode(model.getUnitCode());
            if(Constants.equalsInteger(model.getStatus(),Constants.TWO)){
                shop.setIsdeleted(Constants.ONE);
            }else{
                shop.setIsdeleted(Constants.ZERO);
            }
            shop.setStatus(model.getStatus());
            shop.setAttribute(model.getAttribute());
            shop.setParentIamId(model.getParentOrgId());
            updateList.add(shop);
        }
        return  shop;
    }
 
    private Shop getShopByOrgID(String orgId, List<Shop> list) {
        if(list ==null || list.size() ==0){
            return null;
        }
        for(Shop s :list){
            if(StringUtils.equals(s.getOrgId(),orgId)){
                return s;
            }
        }
        return null;
    }
 
    @Override
    public void updateSort(UpdateShopSortDTO dto) {
        Shop shop = shopMapper.selectById(dto.getId());
        if(Objects.isNull(shop)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
 
        List<Shop> shopPool;
        if (shop.getParentId() == null) {
            shopPool = shopMapper.selectList(new QueryWrapper<Shop>().lambda()
                    .eq(Shop::getIsdeleted,Constants.ZERO)
                    .isNull(Shop::getParentId)
                    .orderByAsc(Shop::getOrderNum)
            );
        } else {
            shopPool = shopMapper.selectList(new QueryWrapper<Shop>().lambda()
                    .eq(Shop::getIsdeleted,Constants.ZERO)
                    .eq(Shop::getParentId,shop.getParentId())
                    .orderByAsc(Shop::getOrderNum)
            );
        }
        int currentMenuIndex = 0;
        for (int i = 0; i < shopPool.size(); i++) {
            if (shopPool.get(i).getId().equals(dto.getId())) {
                currentMenuIndex = i;
                break;
            }
        }
        // 上移
        if ("top".equals(dto.getDirection())) {
            if (currentMenuIndex - 1 < 0) {
                return;
            }
            Shop preMenu = shopPool.get(currentMenuIndex - 1);
            shopPool.remove(currentMenuIndex - 1);
            shopPool.add(currentMenuIndex, preMenu);
        }
        // 下移
        else {
            if (currentMenuIndex + 1 > shopPool.size() - 1) {
                return;
            }
            Shop nextMenu = shopPool.remove(currentMenuIndex + 1);
            shopPool.add(currentMenuIndex, nextMenu);
        }
        for (int i = 0; i < shopPool.size(); i++) {
            shopPool.get(i).setOrderNum(i);
        }
 
        for (Shop updShop:shopPool) {
            shopMapper.updateById(updShop);
        }
    }
    @Override
    public   List<ShopTreeVo> shopTree(Integer type){
        MPJLambdaWrapper<Shop> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Shop.class);
        queryWrapper.select("t1.name_path",Shop::getParentNamePath);
        queryWrapper.select("t1.id_path",Shop::getParentIdPath);
        queryWrapper.select("t1.type",Shop::getParentType);
        queryWrapper.leftJoin(Shop.class,Shop::getId,Shop::getParentId);
        queryWrapper.eq(Shop::getIsdeleted, Constants.ZERO);
        queryWrapper.eq(type!=null,Shop::getType,type);
        queryWrapper.orderByAsc(true,"t.order_num");
        List<ShopTreeVo> shopList = shopMapper.selectJoinList(ShopTreeVo.class,queryWrapper);
        ShopTree treeBuild = new ShopTree(shopList);
        shopList = treeBuild.buildTree();
        return shopList;
    }
    @Override
    public   List<ShopTreeVo> shopTreeCache(Integer type){
 
        return (List<ShopTreeVo>) redisTemplate.opsForValue().get(Constants.RedisKeys.SHOP_TREE);
    }
    @Override
    @Async
    public   void dealShopNamePath(){
        redisTemplate.opsForValue().set(Constants.RedisKeys.IMPORTING_SHOP,true);
        try {
            List<ShopTreeVo> shopList = shopTree(null);
            updateNamePath(null,shopList);
        }catch (Exception e){
 
        }finally {
 
            redisTemplate.opsForValue().set(Constants.RedisKeys.IMPORTING_SHOP,false);
        }
 
    }
    /**
     * 递归处理组织编码和名称完整路径问题
     * @param parent
     * @param shopList
     */
    private void updateNamePath(Shop parent,List<ShopTreeVo> shopList) {
        if(shopList!=null && shopList.size()>0){
            for(ShopTreeVo shop : shopList){
                Shop s = new Shop();
                s.setId(shop.getId());
                s.setName(shop.getName());
                if(parent == null){
                    s.setNamePath(s.getName());
                    s.setIdPath(s.getId()+"/");
                    shopMapper.updateById(s);
                }else{
                    s.setParentId(parent.getId());
                    s.setNamePath(parent.getNamePath()+"/"+s.getName());
                    s.setIdPath(parent.getIdPath()+s.getId()+"/");
                    shopMapper.updateById(s);
                }
                if(shop.getChildList()!=null && shop.getChildList().size()>0){
                    updateNamePath(s,shop.getChildList());
                }
            }
        }
    }
}