郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
package com.gkhy.safePlatform.specialWork.service.baseService.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.specialWork.entity.SpecialWorkAppointmentInfo;
import com.gkhy.safePlatform.specialWork.enums.SpecialWorkAppointmentStatusEnum;
import com.gkhy.safePlatform.specialWork.model.bo.WorkStatisticsBO;
import com.gkhy.safePlatform.specialWork.model.query.SpecialWorkAppointmentQuery;
import com.gkhy.safePlatform.specialWork.repository.SpecialWorkAppointmentInfoRepository;
import com.gkhy.safePlatform.specialWork.service.baseService.SpecialWorkAppointmentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
 
@Service("SpecialWorkAppointmentInfoService")
public class SpecialWorkAppointmentInfoServiceImpl extends ServiceImpl<SpecialWorkAppointmentInfoRepository, SpecialWorkAppointmentInfo> implements SpecialWorkAppointmentInfoService {
    @Autowired
    private SpecialWorkAppointmentInfoRepository repository;
 
 
    /**
     * 新增
     * @param appointmentInfo
     * @return
     */
    @Override
    public int saveOne(SpecialWorkAppointmentInfo appointmentInfo) {
        appointmentInfo.setGmtCreate(LocalDateTime.now());
        appointmentInfo.setStatus(SpecialWorkAppointmentStatusEnum.VALID.getCode());
        return baseMapper.saveOne(appointmentInfo);
    }
 
    /**
     * 修改
     * @param appointmentInfo
     * @return
     */
    @Override
    public int updateOne(SpecialWorkAppointmentInfo appointmentInfo) {
        if (appointmentInfo.getId() == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        appointmentInfo.setGmtModified(LocalDateTime.now());
        return baseMapper.updateOne(appointmentInfo);
    }
 
    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public int updateStatus(Long id) {
        if (id == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return baseMapper.updateStatus(id,SpecialWorkAppointmentStatusEnum.ABANDONED.getCode());
    }
    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Override
    public int updateStatusByIds(List<Long> ids) {
        if (ids == null || ids.size()==0) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return baseMapper.updateStatusByIds(ids,SpecialWorkAppointmentStatusEnum.ABANDONED.getCode());
    }
    /**
     * 查询一条
     * @param id
     * @return
     */
    @Override
    public SpecialWorkAppointmentInfo queryById(Long id) {
        if (id == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return baseMapper.queryById(id,SpecialWorkAppointmentStatusEnum.VALID.getCode());
    }
 
    /**
     * 分页查询
     * @param page
     * @param query
     * @return
     */
    @Override
    public List<SpecialWorkAppointmentInfo> listByPage(IPage<SpecialWorkAppointmentInfo> page, SpecialWorkAppointmentQuery query) {
        query.setStatus(SpecialWorkAppointmentStatusEnum.VALID.getCode());
        return baseMapper.listByConditions(page,query);
    }
 
    /**
     * 列表查询
     * @param query
     * @return
     */
    @Override
    public List<SpecialWorkAppointmentInfo> list(SpecialWorkAppointmentQuery query) {
        query.setStatus(SpecialWorkAppointmentStatusEnum.VALID.getCode());
        return baseMapper.listByConditions(query);
    }
 
    @Override
    public Long getCountByDepAndTime(Long depId, Date appointmentTime) {
        if(null == depId || null == appointmentTime){
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        Long count = baseMapper.selectCount(new LambdaQueryWrapper<SpecialWorkAppointmentInfo>()
                .eq(SpecialWorkAppointmentInfo::getApplyDepId, depId)
                .eq(SpecialWorkAppointmentInfo::getAppointmentTime, appointmentTime)
                .eq(SpecialWorkAppointmentInfo::getStatus, SpecialWorkAppointmentStatusEnum.VALID.getCode())
        );
        return count;
    }
 
    @Override
    public List<WorkStatisticsBO> statisticsAppointment(SpecialWorkAppointmentQuery query) {
        return baseMapper.statisticsAppointment(query,SpecialWorkAppointmentStatusEnum.VALID.getCode());
    }
}