zhongrj
2023-11-07 181cbe8a1b027903dd5295b28fe2d77bad11b9cd
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
/*
 *      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.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springblade.common.node.TreeNode;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.place.entity.PlaceEntity;
import org.springblade.modules.place.entity.PlacePoiLabel;
import org.springblade.modules.place.service.IPlacePoiLabelService;
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.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Arrays;
import java.util.Date;
import java.util.List;
 
/**
 * 场所表 服务实现类
 *
 * @author BladeX
 * @since 2023-10-28
 */
@Service
@AllArgsConstructor
public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, PlaceEntity> implements IPlaceService {
    private final IUserService userService;
    private final IPlacePoiLabelService placePoiLabelService;
 
    @Override
    public IPage<PlaceVO> selectPlacePage(IPage<PlaceVO> page, PlaceVO place) {
        return page.setRecords(baseMapper.selectPlacePage(page, place));
    }
 
    /**
     * 查询场所集合信息
     * @param userId
     * @return
     */
    @Override
    public List<TreeNode> selectPlaceNodeList(Long userId) {
        return baseMapper.selectPlaceNodeList(userId.toString());
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean addVO(PlaceVO placeVO) {
 
        placeVO.setCreateUser(AuthUtil.getUserId());
        placeVO.setCreateTime(new Date());
        placeVO.setUpdateUser(AuthUtil.getUserId());
        placeVO.setUpdateTime(new Date());
 
        //根据手机号查询库里的数据
        User userParams = new User();
        userParams.setPhone(placeVO.getPhone());
        User user = userService.getOne(Condition.getQueryWrapper(userParams));
 
        if (user != null){
            //如果用户存在,则该用户id绑定场所
            placeVO.setPrincipalUserId(user.getId());
        }else{
            //如果用户不存在,则新增一个用户
            User newUser = new User();
            newUser.setAccount(placeVO.getPhone());
            newUser.setPhone(placeVO.getPhone());
 
            newUser.setName(placeVO.getUsername());
            newUser.setRealName(placeVO.getUsername());
            newUser.setRoleId("1717429193350434818");
            newUser.setPassword("123456");
 
            userService.submit(newUser);
            //绑定id
            placeVO.setPrincipalUserId(newUser.getId());
        }
 
        boolean save = save(placeVO);
 
 
        List<String> labelList = Arrays.asList(placeVO.getLabel().split(","));
 
        labelList.forEach(labelId->{
            PlacePoiLabel placePoiLabel = new PlacePoiLabel();
            placePoiLabel.setPlaceId(placeVO.getId());
            placePoiLabel.setPoiCode(Integer.parseInt(labelId));
            placePoiLabelService.save(placePoiLabel);
        });
 
 
        return save;
    }
 
 
}