fei
22 小时以前 9b1b0782ecb77d6ee958774da94606478482b063
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
package com.ruoyi.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.ArchiveAnnotation;
import com.ruoyi.domain.ArchiveSignature;
import com.ruoyi.mapper.ArchiveAnnotationMapper;
import com.ruoyi.service.IArchiveAnnotationService;
import com.ruoyi.util.ErrorcodeExceptionextends;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
 
@Service
public class ArchiveAnnotationServiceImpl extends ServiceImpl<ArchiveAnnotationMapper, ArchiveAnnotation> implements IArchiveAnnotationService {
 
    private LambdaQueryWrapper<ArchiveAnnotation> buildCondition(ArchiveAnnotation archiveAnnotation) {
        LambdaQueryWrapper<ArchiveAnnotation> lqw = new LambdaQueryWrapper<>();
        lqw.like(!StringUtils.isEmpty(archiveAnnotation.getName()), ArchiveAnnotation::getName, archiveAnnotation.getName());
        
        lqw.orderByDesc(ArchiveAnnotation::getSrt);
        return lqw;
    }
 
    @Override
    public ArchiveAnnotation selectArchiveAnnotationById(Long id) {
        LambdaQueryWrapper<ArchiveAnnotation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, ArchiveAnnotation::getId, id);
        List<ArchiveAnnotation> lists = this.list(lqw);
        if (!lists.isEmpty())
            return lists.get(0);
        else
            return null;
    }
 
    @Override
    public AjaxResult selectArchiveAnnotationList(ArchiveAnnotation archiveAnnotation, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<ArchiveAnnotation> lqw = buildCondition(archiveAnnotation);
 
 
        Page<ArchiveAnnotation> archiveSignaturePage = new Page<>(pageNum, pageSize);
        Page<ArchiveAnnotation> pageResult = page(archiveSignaturePage, lqw);
 
        List<ArchiveAnnotation> beanRecords = pageResult.getRecords();//得到查询出来的数据
 
 
 
        //  List<ArchiveRecords> beanRecords = list(lqw);
        //   log.info("从数据库中查到的为:{}", beanRecords);
        //    return markOwnData(familyId, fatherFaId, motherFaId, beanRecords);
        HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords);
 
 
        return AjaxResult.success(data);
    }
 
    @Override
    public List<ArchiveAnnotation> selectArchiveAnnoList(ArchiveAnnotation archiveAnnotation) {
        return Collections.emptyList();
    }
 
    @Override
    public int insertArchiveAnnotation(ArchiveAnnotation archiveAnnotation) {
        LocalDateTime time = LocalDateTime.now();
        if (archiveAnnotation.getName() == null || StringUtils.isEmpty(archiveAnnotation.getName()))
            throw new RuntimeException("注解名称不能为空!");
        Date date = Date.from(time.atZone(ZoneId.systemDefault()).toInstant());
        archiveAnnotation.setCreateTime(date);
        
        // 根据注解名称查询,是否已经存在,存在的话不让插入
        LambdaQueryWrapper<ArchiveAnnotation> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(!StringUtils.isEmpty(archiveAnnotation.getName()), ArchiveAnnotation::getName, 
                archiveAnnotation.getName());
        List<ArchiveAnnotation> lis = list(lambdaQueryWrapper);
        if (!lis.isEmpty()) {
            return 0;
        }
        
        boolean res = this.save(archiveAnnotation);
        
        // 0表示失败,1表示成功
        if (res)
            return 1;
        else
            return 0;
    }
 
    @Override
    public int updateArchiveAnnotation(ArchiveAnnotation archiveAnnotation) {
        boolean result = false;
        try {
            // 使用LambdaUpdateWrapper构造更新条件,确保null值也能更新到数据库
            LambdaUpdateWrapper<ArchiveAnnotation> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(ArchiveAnnotation::getId, archiveAnnotation.getId());
 
            // 明确设置需要更新的字段
            updateWrapper.set(ArchiveAnnotation::getName, archiveAnnotation.getName());
            updateWrapper.set(ArchiveAnnotation::getSrt, archiveAnnotation.getSrt());
            updateWrapper.set(ArchiveAnnotation::getCreateTime, archiveAnnotation.getCreateTime());
 
            // 执行更新操作
            result = update(updateWrapper);
        } catch (Exception e) {
            System.out.println(e);
            throw new ErrorcodeExceptionextends(500, "不允许注解名称重复!");
        }
        if (result)
            return 1;
        else
            return 0;
    }
 
    @Override
    public int deleteArchiveAnnotationByIds(Long[] ids) {
        if (this.removeByIds(Arrays.asList(ids))) {
            return 1;
        } else {
            return 0;
        }
    }
 
    @Override
    public int deleteArchiveAnnotationById(Long id) {
        return this.baseMapper.deleteById(id);
    }
}