kongzy
2023-09-22 3124f3a5b7f45d043b228829b6b3a2e541b31574
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
package com.nms.swspkmas_standalone.service.impl;
 
import com.nms.swspkmas_standalone.entity.ExamRoom;
import com.nms.swspkmas_standalone.entity.vo.ExamRoomVO;
import com.nms.swspkmas_standalone.exception.ApiException;
import com.nms.swspkmas_standalone.mapper.ExamRoomMapper;
import com.nms.swspkmas_standalone.service.ExamRoomService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import java.sql.Wrapper;
import java.time.LocalDateTime;
import java.util.List;
 
/**
 * <p>
 * 考场信息 服务实现类
 * </p>
 *
 * @author kzy
 * @since 2023-09-20 16:13:59
 */
@Service
public class ExamRoomServiceImpl extends ServiceImpl<ExamRoomMapper, ExamRoom> implements ExamRoomService {
 
    @Override
    public void addExamRoom(ExamRoomVO examRoomVO) {
        Long count=count();
        if(count>1){
            throw new ApiException("已存在考场信息");
        }
        ExamRoom examRoom=new ExamRoom();
        BeanUtils.copyProperties(examRoomVO,examRoom);
        save(examRoom);
    }
 
    @Override
    public void updateExamRoom(Long id, ExamRoomVO examRoomVO) {
        ExamRoom examRoom=getById(id);
        if(examRoom==null){
            throw new ApiException("考场信息不存在");
        }
        BeanUtils.copyProperties(examRoomVO,examRoom,new String[]{"id"});
        examRoom.setUpdateTime(LocalDateTime.now());
        updateById(examRoom);
    }
 
    @Override
    public void deleteExamRoom() {
        baseMapper.deleteExamRoom();
    }
 
    @Override
    public ExamRoom getExamRoom() {
        List<ExamRoom> examRoomList=list();
        if(examRoomList.size()>1){
            throw new ApiException("考场信息存在多条记录");
        }
        return examRoomList.size()==1?examRoomList.get(0):null;
    }
}