fei
18 小时以前 cb703ae5b5afdd4a7d614a948ee4d4c457b77185
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
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.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.ArchiveAnnotation;
import com.ruoyi.domain.ArchivePlaceName;
import com.ruoyi.domain.ArchiveRecords;
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 org.springframework.web.multipart.MultipartFile;
 
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 List<ArchiveAnnotation> selectArchiveRecordsByIds(Long[] ids) {
 
        // 创建查询条件
        LambdaQueryWrapper<ArchiveAnnotation> lambdaQueryWrapper = new LambdaQueryWrapper<>();
 
        // 根据ids查询
        lambdaQueryWrapper.in(ArchiveAnnotation::getId, Arrays.asList(ids));
 
        // 如果不是管理员,需要考虑权限过滤(可根据实际权限需求调整)
//        if (userid != 1) {
//            // 这里可以添加权限相关的过滤条件
//        }
 
        List<ArchiveAnnotation> beanRecords = list(lambdaQueryWrapper);
        return beanRecords;
    }
 
    @Override
    public AjaxResult importExcel(MultipartFile file) {
        ExcelUtil<ArchiveAnnotation> util = new ExcelUtil<>(ArchiveAnnotation.class);
        List<ArchiveAnnotation> dataList = null;
        try {
            dataList = util.importExcel(file.getInputStream());
        } catch (Exception e) {
            throw new RuntimeException("没有按照规则导入数据");
        }
 
        assert dataList != null;
 
        for (ArchiveAnnotation archiveAnnotation : dataList) {
            // physcialService.mySave(physcial);
            this.insertArchiveAnnotation(archiveAnnotation);
        }
 
        return AjaxResult.success();
    }
 
    @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) {
        LambdaQueryWrapper<ArchiveAnnotation> lqw = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<ArchiveAnnotation> lambdaQueryWrapper = buildCondition(archiveAnnotation);
        List<ArchiveAnnotation> beanRecords = list(lambdaQueryWrapper);
        return beanRecords;
    }
 
    @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);
    }
}