zhongrj
2023-12-23 d82e3ef630a132309f9f7b435ae395df7b99bcf5
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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.place.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springblade.common.node.TreeStringNode;
import org.springblade.common.utils.IdUtils;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity;
import org.springblade.modules.doorplateAddress.service.IDoorplateAddressService;
import org.springblade.modules.grid.entity.GridRangeEntity;
import org.springblade.modules.grid.service.IGridRangeService;
import org.springblade.modules.grid.service.IGridService;
import org.springblade.modules.grid.vo.GridVO;
import org.springblade.modules.place.entity.*;
import org.springblade.modules.place.excel.PlaceAndRelExcel;
import org.springblade.modules.place.excel.PlaceExcel;
import org.springblade.modules.place.service.IPlaceExtService;
import org.springblade.modules.place.service.IPlacePoiLabelService;
import org.springblade.modules.place.service.IPlaceRelService;
import org.springblade.modules.place.vo.PlaceVO;
import org.springblade.modules.place.mapper.PlaceMapper;
import org.springblade.modules.place.service.IPlaceService;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
 
/**
 * 场所表 服务实现类
 *
 * @author BladeX
 * @since 2023-10-28
 */
@Service
public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, PlaceEntity> implements IPlaceService {
    @Autowired
    private IUserService userService;
 
    @Autowired
    private IPlacePoiLabelService placePoiLabelService;
 
    @Autowired
    private IPlaceExtService placeExtService;
 
    @Autowired
    private IPlaceRelService placeRelService;
 
    @Autowired
    private IDoorplateAddressService doorplateAddressService;
 
    @Autowired
    private IGridService gridService;
 
    @Autowired
    private IGridRangeService gridRangeService;
 
    /**
     * 自定义列表查询
     * @param page
     * @param place
     * @return
     */
    @Override
    public IPage<PlaceVO> selectPlacePage(IPage<PlaceVO> page, PlaceVO place) {
        List<String> list = new ArrayList<>();
        if (null!=place.getRoleName() && !place.getRoleName().equals("")){
            if (place.getRoleName().equals("网格员")){
                // 查询对应的房屋地址code
                list = gridService.getAddressCodeListByUserId(AuthUtil.getUserId());
                place.setCreateUser(AuthUtil.getUserId());
            }
            if (!place.getRoleName().equals("系统管理员")){
                place.setCreateUser(AuthUtil.getUserId());
            }
        }
        List<PlaceVO> placeVOS = baseMapper.selectPlacePage(page, place, list);
        // 遍历
        for (PlaceVO placeVO : placeVOS) {
            // 设置对应的网格名称
            GridVO gridVO = gridService.getGridDetailByHouseCode(placeVO.getHouseCode());
            if (null!= gridVO){
                placeVO.setGridName(gridVO.getGridName());
//                placeVO.setNeiName(gridVO.getCommunityName());
//                placeVO.setTownStreetName(gridVO.getTownStreetName());
            }
        }
        // 返回
        return page.setRecords(placeVOS);
    }
 
    /**
     * 查询场所集合信息
     * @param userId
     * @return
     */
    @Override
    public List<TreeStringNode> selectPlaceNodeList(Long userId) {
        return baseMapper.selectPlaceNodeList(userId.toString());
    }
 
    /**
     * 场所信息自定义新增/修改
     * @param placeVO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean addOrUpdate(PlaceVO placeVO) {
        boolean flag = false;
        placeVO.setUpdateUser(AuthUtil.getUserId());
        placeVO.setUpdateTime(new Date());
        // 查看是否包含houseCode,如果有,则更新
        if (!Strings.isBlank(placeVO.getHouseCode())){
            // 更新,先查询场所信息
            QueryWrapper<PlaceEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("is_deleted",0).eq("house_code",placeVO.getHouseCode());
            PlaceEntity one = getOne(wrapper);
            if (null!=one) {
                placeVO.setId(one.getId());
            }
            // 设置来源( 1:地址总表  2:国控采集),扫码采集
            placeVO.setSource(1);
            // 绑定用户信息
            bindUserHandle(placeVO);
            // 更新场所信息
            flag = updateById(placeVO);
            // 保存场所详情及任务信息
            savePlaceExtAndTaskInfo(placeVO);
            // 场所标签信息绑定(更新,调整)
            placeLabelBind(placeVO);
            // 网格绑定
            gridBind(placeVO);
        }else {
            // 设置基础数据
            placeVO.setCreateUser(AuthUtil.getUserId());
            placeVO.setCreateTime(new Date());
            // 设置来源( 1:地址总表  2:国控采集)
            placeVO.setSource(2);
            // 并生成36位的houseCode
            placeVO.setHouseCode(IdUtils.getIdBy36());
            // 绑定用户信息
            bindUserHandle(placeVO);
            // 新增场所信息
            flag = save(placeVO);
            // 保存场所详情及任务信息
            savePlaceExtAndTaskInfo(placeVO);
            // 场所标签信息绑定
            placeLabelBind(placeVO);
            // 网格绑定
            gridBind(placeVO);
        }
        // 位置绑定,通过定位去匹配所在网格
        // 返回结果
        return flag;
    }
 
    /**
     * 网格绑定
     * @param placeVO
     */
    public void gridBind(PlaceVO placeVO) {
        if (null!=placeVO.getGridId()){
            // 判断关联关系表是否存在
            QueryWrapper<GridRangeEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("grid_id",placeVO.getGrid()).eq("house_code",placeVO.getHouseCode());
            GridRangeEntity one = gridRangeService.getOne(wrapper);
            if (null==one){
                // 新增
                GridRangeEntity gridRangeEntity = new GridRangeEntity();
                gridRangeEntity.setHouseCode(placeVO.getHouseCode());
                gridRangeEntity.setGridId(placeVO.getGridId());
                // 插入
                gridRangeService.save(gridRangeEntity);
            }
        }
    }
 
    /**
     * 场所标签信息绑定入库
     * @param placeVO
     */
    @Transactional(rollbackFor = Exception.class)
    public void placeLabelBind(PlaceVO placeVO) {
        // 先查询对于的场所是否已有标签信息
        // 查询对应已存在的从业人员
        QueryWrapper<PlacePoiLabel> wrapper = new QueryWrapper<>();
        wrapper.eq("place_id",placeVO.getId());
        List<PlacePoiLabel> oldList = placePoiLabelService.list(wrapper);
        if (oldList.size()>0){
            // 先将老的全部删除,然后批量插入
            QueryWrapper<PlacePoiLabel> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("place_id",placeVO.getId());
            boolean remove = placePoiLabelService.remove(queryWrapper);
            if (remove){
                // 批量新增
                savePlaceLabel(placeVO);
            }
        }else {
            savePlaceLabel(placeVO);
        }
    }
 
    /**
     * 插入场所标签信息
     * @param placeVO
     */
    public void savePlaceLabel(PlaceVO placeVO) {
        // 批量新增
        List<String> labelList = Arrays.asList(placeVO.getLabel().split(","));
        if (labelList.size()>1){
            // 只处理小类
            // 遍历
            labelList.forEach(labelId -> {
                // 处理小类
                if (labelId.length()>4) {
                    // 切割成三个,分别是大类,中类,小类
                    String bigString = labelId.substring(0,2);
                    String midString = labelId.substring(0,4);
                    // 大类
                    PlacePoiLabel big = new PlacePoiLabel();
                    big.setPlaceId(placeVO.getId());
                    big.setPoiCode(Integer.parseInt(bigString));
                    big.setType(1);
                    placePoiLabelService.save(big);
                    // 中类
                    PlacePoiLabel mid = new PlacePoiLabel();
                    mid.setPlaceId(placeVO.getId());
                    mid.setPoiCode(Integer.parseInt(midString));
                    mid.setType(2);
                    placePoiLabelService.save(mid);
                    // 小类
                    PlacePoiLabel min = new PlacePoiLabel();
                    min.setPlaceId(placeVO.getId());
                    min.setPoiCode(Integer.parseInt(labelId));
                    min.setType(3);
                    placePoiLabelService.save(min);
                }
            });
        }else {
            // 处理单个
            String labelCode = labelList.get(0);
            // 切割成三个,分别是大类,中类,小类
            String bigString = labelCode.substring(0,2);
            String midString = labelCode.substring(0,4);
            // 大类
            PlacePoiLabel big = new PlacePoiLabel();
            big.setPlaceId(placeVO.getId());
            big.setPoiCode(Integer.parseInt(bigString));
            big.setType(1);
            placePoiLabelService.save(big);
            // 中类
            PlacePoiLabel mid = new PlacePoiLabel();
            mid.setPlaceId(placeVO.getId());
            mid.setPoiCode(Integer.parseInt(midString));
            mid.setType(2);
            placePoiLabelService.save(mid);
            // 处理小类
            if (labelCode.length()>4) {
                // 小类
                PlacePoiLabel min = new PlacePoiLabel();
                min.setPlaceId(placeVO.getId());
                min.setPoiCode(Integer.parseInt(labelCode));
                min.setType(3);
                placePoiLabelService.save(min);
            }
        }
    }
 
    /**
     * 场所负责人和用户绑定
     * @param placeVO
     */
    @Transactional(rollbackFor = Exception.class)
    public User bindUserHandle(PlaceVO placeVO) {
        User newUser = new User();
        if (null!=placeVO.getPhone() && !placeVO.getPhone().equals("")) {
            placeVO.setPrincipal(placeVO.getUsername());
            placeVO.setPrincipalPhone(placeVO.getPhone());
            //根据手机号查询库里的数据
            User userParams = new User();
            userParams.setPhone(placeVO.getPhone());
            User user = userService.getOne(Condition.getQueryWrapper(userParams));
 
            if (null!=user) {
                //如果用户存在,则该用户id绑定场所
                placeVO.setPrincipalUserId(user.getId());
                newUser = user;
                // 判断用户是否包含了居民角色,不包含则需更新
                if (!user.getRoleId().contains("1717429059648606209")){
                    user.setRoleId(user.getRoleId() + ",1717429059648606209");
                    //更新
                    userService.updateById(user);
                }
            } else {
                //如果用户不存在,则新增一个用户
                newUser.setAccount(placeVO.getPhone());
                newUser.setPhone(placeVO.getPhone());
                newUser.setName(placeVO.getUsername());
                newUser.setRealName(placeVO.getUsername());
                // 社区群众部门
                newUser.setDeptId("1727979636479037441");
                // 目前暂定居民角色,
                newUser.setRoleId("1717429059648606209");
                //默认密码为 123456
                newUser.setPassword("123456");
                // 设置机构
                // 用户新增
                boolean submit = userService.submit(newUser);
                //绑定id
                placeVO.setPrincipalUserId(newUser.getId());
                //给人员打上场所负责人的标签
                baseMapper.saveUserLabel(newUser.getId(),1002);
            }
        }
        return newUser;
    }
 
    /**
     * 保存场所详情及任务信息
     * @param placeVO
     */
    @Transactional(rollbackFor = Exception.class)
    public void savePlaceExtAndTaskInfo(PlaceVO placeVO) {
        PlaceExtEntity placeExtEntity = new PlaceExtEntity();
        placeExtEntity.setPlaceId(placeVO.getId());
        // 判断是否已存在,已存在则不新增
        QueryWrapper<PlaceExtEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted",0)
            .eq("place_id",placeVO.getId());
        PlaceExtEntity one = placeExtService.getOne(wrapper);
        if (null == one) {
            placeExtEntity.setPlaceId(placeVO.getId());
            //新增
            placeExtService.savePlaceExt(placeExtEntity);
        }
    }
 
    /**
     * 历史场所挂接处理-临时
     * @param place
     * @return
     */
    @Override
    public Object historyPlaceHandle(PlaceVO place) {
        // 查询所有的场所(手机号不为空)
        List<PlaceVO> list = baseMapper.getPlaceNotNullPhone();
        // 遍历
        for (PlaceVO placeVO : list) {
            User user = bindUserHandle(placeVO);
            if (null!=user){
                placeVO.setPrincipalUserId(user.getId());
                //更新场所用户id绑定
                baseMapper.updatePlaceEntity(placeVO);
            }
        }
        return null;
    }
 
    /**
     * 历史场所标签挂接处理-临时
     * @param place
     * @return
     */
    @Override
    @Transactional
    public Object historyPlaceLabelHandle(PlaceVO place) {
        // 查询所有的场所
        List<PlaceVO> list = baseMapper.getAllHistoryPlace();
        // 遍历
        for (PlaceVO placeVO : list) {
            if (null!=placeVO.getLabel()){
                String[] split = placeVO.getLabel().split(",");
                for (String s : split) {
                    PlacePoiLabel placePoiLabel = new PlacePoiLabel();
                    placePoiLabel.setPlaceId(placeVO.getId());
                    placePoiLabel.setPoiCode(Integer.parseInt(s));
                    placePoiLabelService.save(placePoiLabel);
                }
            }
        }
        return null;
    }
 
    /**
     * 场所表 自定义详情查询
     * @param place
     * @return
     */
    @Override
    public PlaceVO getDetail(PlaceVO place) {
        // 查询场所信息
        PlaceVO placeVO = baseMapper.getDetail(place);
        if (null!= place.getAddressType() && place.getAddressType()==4){
            if (null != placeVO) {
                // 查询地址编码信息(社区派出所相关信息)
                DoorplateAddressEntity addressEntity = placeRelService.getDoorplateAddressEntity(placeVO);
                placeVO.setDoorplateAddressEntity(addressEntity);
                // 查询网格信息
                placeVO.setGrid(gridService.getGridDetailByParam(placeVO));
            }
        }else {
            if (null != placeVO) {
                if (null != placeVO.getHouseCode() && !placeVO.getHouseCode().equals("")) {
                    place.setHouseCode(placeVO.getHouseCode());
                }
                // 查询门牌地址信息
                if (null != place.getHouseCode() && !place.getHouseCode().equals("")) {
                    QueryWrapper<DoorplateAddressEntity> wrapper = new QueryWrapper<>();
                    wrapper.eq("address_code", place.getHouseCode());
                    List<DoorplateAddressEntity> list = doorplateAddressService.list(wrapper);
                    if (list.size() > 0) {
                        placeVO.setDoorplateAddressEntity(list.get(0));
                        placeVO.setNeiCode(list.get(0).getNeiCode().replaceAll("0+$", ""));
                    }
                    // 查询网格数据
                    GridVO gridVO = gridService.getGridDetailByHouseCode(place.getHouseCode());
                    if (null!= gridVO) {
                        placeVO.setGrid(gridVO);
                        place.setGridId(gridVO.getId());
                    }
                } else {
                    // 通过定位点落面分析网格位置,反向推出社区派出所相关数据
 
                }
            }
        }
        // 返回
        return placeVO;
    }
 
    /**
     * 场所数据到导入
     * @param data
     * @param isCovered
     */
    @Override
    public void importPlace(List<PlaceExcel> data, Boolean isCovered) {
        for (PlaceExcel placeExcel : data) {
            // 判断是否存在,不存在则插入,否则不操作
            QueryWrapper<PlaceEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("is_deleted",0)
                .eq("house_code",placeExcel.getHouseCode());
            PlaceEntity one = getOne(wrapper);
            if (null == one){
                Long userId = updateUser(placeExcel);
                // 插入场所
                PlaceEntity placeEntity = new PlaceEntity();
                placeEntity.setHouseCode(placeExcel.getHouseCode());
                placeEntity.setPrincipalUserId(userId);
                placeEntity.setPrincipal(placeExcel.getName());
                placeEntity.setPrincipalPhone(placeExcel.getPhoneNumber());
                placeEntity.setCreateTime(new Date());
                placeEntity.setCreateUser(AuthUtil.getUserId());
                placeEntity.setUpdateTime(new Date());
                placeEntity.setUpdateUser(AuthUtil.getUserId());
                //一个一个插入,防止同一个表中有相同的数据
                save(placeEntity);
            }
        }
    }
 
    /**
     * 更新用户信息
     * @param placeExcel
     * @return
     */
    public Long updateUser(PlaceExcel placeExcel) {
        if (!Strings.isBlank(placeExcel.getPhoneNumber()) &&
            !Strings.isBlank(placeExcel.getName())) {
            PlaceVO placeVO = new PlaceVO();
            placeVO.setPhone(placeExcel.getPhoneNumber());
            placeVO.setUsername(placeExcel.getName());
            // 更新场所负责人
            User user = bindUserHandle(placeVO);
            // 返回
            return user.getId();
        }
        return null;
    }
 
    /**
     * 更新用户信息
     * @param placeExcel
     * @return
     */
    public Long updateUser(PlaceAndRelExcel placeExcel) {
        if (!Strings.isBlank(placeExcel.getPhoneNumber()) &&
            !Strings.isBlank(placeExcel.getName())) {
            PlaceVO placeVO = new PlaceVO();
            placeVO.setPhone(placeExcel.getPhoneNumber());
            placeVO.setUsername(placeExcel.getName());
            // 更新场所负责人
            User user = bindUserHandle(placeVO);
            // 返回
            return user.getId();
        }
        return null;
    }
 
    /**
     * 场所(商超)导入
     * @param data
     * @param isCovered
     */
    @Override
    public void importAndRelPlace(List<PlaceAndRelExcel> data, Boolean isCovered) {
        for (PlaceAndRelExcel placeExcel : data) {
            // 判断是否存在,不存在则插入,否则不操作
            PlaceEntity one = baseMapper.getPlaceAndRelInfo(placeExcel);
            if (null == one){
                Long userId = updateUser(placeExcel);
                // 插入场所
                PlaceEntity placeEntity = new PlaceEntity();
                placeEntity.setPlaceName(placeExcel.getPlaceName());
                placeEntity.setLocaltion(placeExcel.getAddress());
                placeEntity.setPrincipalUserId(userId);
                placeEntity.setPrincipal(placeExcel.getName());
                placeEntity.setPrincipalPhone(placeExcel.getPhoneNumber());
                placeEntity.setPrincipalUserId(userId);
                placeEntity.setCreateTime(new Date());
                placeEntity.setCreateUser(AuthUtil.getUserId());
                placeEntity.setUpdateTime(new Date());
                placeEntity.setUpdateUser(AuthUtil.getUserId());
                //一个一个插入,防止同一个表中有相同的数据
                save(placeEntity);
                // 插入标签关系表
                savPlaceLabelBind(placeExcel,placeEntity);
                // 插入关联数据表
                PlaceRelEntity placeRelEntity = new PlaceRelEntity();
                placeRelEntity.setPlaceId(placeEntity.getId());
                placeRelEntity.setStreetName(placeExcel.getStreetName());
                placeRelEntity.setCommunityName(placeExcel.getCommunityName());
                placeRelEntity.setGridName(placeExcel.getGridName());
                placeRelEntity.setBuildingName(placeExcel.getBuildingName());
                placeRelEntity.setDoorplateNum(placeExcel.getDoorplateNum());
                placeRelEntity.setFloor(placeExcel.getFloor());
                placeRelEntity.setCreateTime(new Date());
                placeRelEntity.setCreateUser(AuthUtil.getUserId());
                placeRelEntity.setUpdateTime(new Date());
                placeRelEntity.setUpdateUser(AuthUtil.getUserId());
                // 新增
                placeRelService.save(placeRelEntity);
            }else {
                // 只更新商铺信息
                Long userId = updateUser(placeExcel);
                // 插入场所
                PlaceEntity placeEntity = new PlaceEntity();
                placeEntity.setId(one.getId());
                placeEntity.setPlaceName(placeExcel.getPlaceName());
                placeEntity.setLocaltion(placeExcel.getAddress());
                placeEntity.setPrincipalUserId(userId);
                placeEntity.setCreateTime(new Date());
                placeEntity.setCreateUser(AuthUtil.getUserId());
                placeEntity.setUpdateTime(new Date());
                placeEntity.setUpdateUser(AuthUtil.getUserId());
                //一个一个插入,防止同一个表中有相同的数据
                updateById(placeEntity);
            }
        }
    }
 
    /**
     * 插入标签关系表
     * @param placeExcel
     */
    public void savPlaceLabelBind(PlaceAndRelExcel placeExcel,PlaceEntity placeEntity) {
        if (!Strings.isBlank(placeExcel.getLabelCode())){
            PlaceVO placeVO = new PlaceVO();
            placeVO.setId(placeEntity.getId());
            placeVO.setLabel(placeExcel.getLabelCode());
            // 插入标签
            placeLabelBind(placeVO);
        }
    }
 
    /**
     * 场所数据处理-用户信息(场所负责人信息写入到场所表)
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Object placeUserHandle() {
        // 查询出有用户id 的场所
        List<PlaceEntity> list = baseMapper.getHasUserIdPlaceList();
        // 遍历
        for (PlaceEntity placeEntity : list) {
            // 查询对应的用户信息
            User user = userService.getById(placeEntity.getPrincipalUserId());
            if (null!=user) {
                // 设置场所负责人,手机号
                if (null != user.getRealName() && !user.getRealName().equals("")) {
                    placeEntity.setPrincipal(user.getRealName());
                }
                if (null != user.getPhone() && !user.getPhone().equals("")) {
                    placeEntity.setPrincipalPhone(user.getPhone());
                }
                // 更新场所信息
                updateById(placeEntity);
            }
        }
        return null;
    }
 
    /**
     * 自定义修改
     * @param placeVO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updatePlace(PlaceVO placeVO) {
        boolean flag = false;
        // 修改场所信息
        flag = updateById(placeVO);
        // 修改标签绑定信息
        // 返回
        return flag;
    }
 
    /**
     * 场所标签数据处理
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Object placeLabelHandle() {
        // 查询所有的标签绑定
        List<PlacePoiLabel> list = placePoiLabelService.getPlacePoiLabelList();
        // 遍历
        for (PlacePoiLabel placePoiLabel : list) {
            // 处理单个
            String labelCode = placePoiLabel.getPoiCode().toString();
            // 切割成三个,分别是大类,中类,小类
            String bigString = labelCode.substring(0,2);
            String midString = labelCode.substring(0,4);
            // 大类
            PlacePoiLabel big = new PlacePoiLabel();
            big.setPlaceId(placePoiLabel.getPlaceId());
            big.setPoiCode(Integer.parseInt(bigString));
            big.setType(1);
            // 保存前先判断
            QueryWrapper<PlacePoiLabel> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("place_id",placePoiLabel.getPlaceId()).eq("poi_code",Integer.parseInt(bigString));
            PlacePoiLabel one = placePoiLabelService.getOne(queryWrapper);
            if (null==one) {
                placePoiLabelService.save(big);
            }
            // 中类
            PlacePoiLabel mid = new PlacePoiLabel();
            mid.setPlaceId(placePoiLabel.getPlaceId());
            mid.setPoiCode(Integer.parseInt(midString));
            mid.setType(2);
            // 保存前先判断
            QueryWrapper<PlacePoiLabel> wrapper = new QueryWrapper<>();
            wrapper.eq("place_id",placePoiLabel.getPlaceId()).eq("poi_code",Integer.parseInt(midString));
            PlacePoiLabel two = placePoiLabelService.getOne(wrapper);
            if (null==two) {
                placePoiLabelService.save(mid);
            }
        }
        return null;
    }
}