zqy
2024-07-28 997b03f08f01f87112227b617e446515b22c6c74
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
package com.ruoyi.service.impl;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.ZfMaster;
import com.ruoyi.domain.ZfPet;
import com.ruoyi.mapper.ZfMasterMapper;
import com.ruoyi.service.ZfMasterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * <p>
 * 魅宠主人表 服务实现类
 * </p>
 *
 * @author ojq
 * @since 2023-03-12
 */
@Service
@Slf4j
public class ZfMasterServiceImpl extends ServiceImpl<ZfMasterMapper, ZfMaster> implements ZfMasterService {
 
    @Override
    public AjaxResult getMasterInfoByPetId(String pid) {
        LambdaQueryWrapper<ZfMaster> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZfMaster::getPetId,pid);
        ZfMaster master = getOne(lqw);
        return AjaxResult.success(master);
    }
 
    @Override
    public List<ZfMaster> selectByCondition(ZfMaster zfMaster) {
        LambdaQueryWrapper<ZfMaster> lambdaQueryWrapper = buildCondition(zfMaster);
        List<ZfMaster> list = list(lambdaQueryWrapper);
        log.info("返回的数据为:{}",list);
        return list;
    }
 
    @Override
    public AjaxResult mySave(ZfMaster zfMaster) {
        //判断是否有重复数据
        LambdaQueryWrapper<ZfMaster> lqw = uniqueCondition(zfMaster);
        List<ZfMaster> list = list(lqw);
        if(list.size()>0){
            throw new RuntimeException("请勿新增重复数据");
        }
 
        if(save(zfMaster)){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
 
    }
 
    private LambdaQueryWrapper<ZfMaster> uniqueCondition(ZfMaster zfMaster) {
        LambdaQueryWrapper<ZfMaster> lqw = new LambdaQueryWrapper<>();
        lqw.eq(zfMaster.getPetId()!=null,ZfMaster::getPetId,zfMaster.getPetId());
        lqw.eq(StringUtils.isNotEmpty(zfMaster.getName()),ZfMaster::getName,zfMaster.getName());
        lqw.eq(StringUtils.isNotEmpty(zfMaster.getCertificateType()),ZfMaster::getCertificateType,zfMaster.getCertificateType());
 
        lqw.eq(StringUtils.isNotEmpty(zfMaster.getPhoneNo()),ZfMaster::getPhoneNo,zfMaster.getPhoneNo());
 
        lqw.eq(StringUtils.isNotEmpty(zfMaster.getAddress()),ZfMaster::getAddress,zfMaster.getAddress());
 
 
        return lqw;
 
    }
 
    private LambdaQueryWrapper<ZfMaster> buildCondition(ZfMaster zfMaster) {
        LambdaQueryWrapper<ZfMaster> lqw = new LambdaQueryWrapper<>();
        lqw.like(zfMaster.getPetId()!=null,ZfMaster::getPetId,zfMaster.getPetId());
        lqw.like(StringUtils.isNotEmpty(zfMaster.getName()),ZfMaster::getName,zfMaster.getName());
        lqw.like(StringUtils.isNotEmpty(zfMaster.getCertificateType()),ZfMaster::getCertificateType,zfMaster.getCertificateType());
 
        lqw.like(StringUtils.isNotEmpty(zfMaster.getPhoneNo()),ZfMaster::getPhoneNo,zfMaster.getPhoneNo());
 
        lqw.like(StringUtils.isNotEmpty(zfMaster.getAddress()),ZfMaster::getAddress,zfMaster.getAddress());
 
        return lqw;
    }
}