huliguo
2 天以前 5d7b65670282a4fad015e37d567cfa171b162052
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
package com.ruoyi.errand.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.errand.constant.DelFlagConstant;
import com.ruoyi.errand.domain.AppUser;
import com.ruoyi.errand.domain.Community;
import com.ruoyi.errand.domain.Phone;
import com.ruoyi.errand.mapper.CommunityMapper;
import com.ruoyi.errand.mapper.PhoneMapper;
import com.ruoyi.errand.service.PhoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
 
@Service
public class PhoneServiceImpl extends ServiceImpl<PhoneMapper, Phone> implements PhoneService {
    @Override
    public String getServletPhone() {
        AppUser appuser = (AppUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        //查找小区客服
        Phone phone = this.getBaseMapper().selectOne(new LambdaUpdateWrapper<Phone>().eq(Phone::getType, 2)
                .eq(Phone::getCommunity_id, appuser.getCommunityId()));
        if (phone!=null){
            return phone.getPhone();
        }
        //查找平台客服
        List<Phone> list = this.getBaseMapper().selectList(new LambdaUpdateWrapper<Phone>().eq(Phone::getType, 1));
        return list.get(0).getPhone();
    }
 
    @Override
    public void saveServicePhone(String phone) {
        Phone phoneEntity = this.getBaseMapper().selectOne(new LambdaUpdateWrapper<Phone>().eq(Phone::getType, 1));
        if (phoneEntity!=null){
            //不存在
            phoneEntity.setType(1);
            phoneEntity.setPhone(phone);
            this.save(phoneEntity);
        }else {
            //存在
            //是否相同
            if(phone.equals(phoneEntity.getPhone())){
                return;
            }
            phoneEntity.setPhone(phone);
            this.updateById(phoneEntity);
        }
    }
 
}