huanghongfa
2021-07-30 c7450a8e1724528046af3683d49eaf0a06785130
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
package com.panzhihua.service_community.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.enums.SafeWordStatusEnum;
import com.panzhihua.common.model.dtos.community.ComSwDangerReportHandleDTO;
import com.panzhihua.common.model.dtos.community.ComSwDangerReportRectifyDTO;
import com.panzhihua.common.model.dtos.community.ComSwPatrolRecordPageDTO;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComMngCarExcelVO;
import com.panzhihua.common.model.vos.community.ComSwDangerReportExcelVO;
import com.panzhihua.common.model.vos.community.ComSwDangerReportVO;
import com.panzhihua.common.model.vos.community.ComSwSafetyWorkRecordVO;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.ComSwDangerReportDAO;
import com.panzhihua.service_community.dao.ComSwPatrolRecordDAO;
import com.panzhihua.service_community.dao.ComSwPatrolRecordReportDAO;
import com.panzhihua.service_community.model.dos.ComSwDangerReportDO;
import com.panzhihua.service_community.model.dos.ComSwPatrolRecordDO;
import com.panzhihua.service_community.model.dos.ComSwPatrolRecordReportDO;
import com.panzhihua.service_community.model.dos.ComSwSafetyWorkRecordDO;
import com.panzhihua.service_community.service.ComSwDangerReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
 * @auther txb
 * @create 2021-07-27 14:31:04
 * @describe 服务实现类
 */
@Slf4j
@Service
public class ComSwDangerReportServiceImpl extends ServiceImpl<ComSwDangerReportDAO, ComSwDangerReportDO> implements ComSwDangerReportService {
 
    @Resource
    private ComSwDangerReportDAO comSwDangerReportDAO;
 
    @Resource
    private ComSwPatrolRecordDAO comSwPatrolRecordDAO;
 
    @Resource
    private ComSwPatrolRecordReportDAO comSwPatrolRecordReportDAO;
 
    @Resource
    private UserService userService;
 
    @Override
    public R pageDangerReport(ComSwPatrolRecordPageDTO comSwPatrolRecordPageDTO) {
        Page page = new Page<>();
        Long pageNum = comSwPatrolRecordPageDTO.getPageNum();
        Long pageSize = comSwPatrolRecordPageDTO.getPageSize();
        if (null == pageNum || 0 == pageNum) {
            pageNum = 1L;
        }
        if (null == pageSize || 0 == pageSize) {
            pageSize = 10L;
        }
        page.setSize(pageSize);
        page.setCurrent(pageNum);
 
        IPage<ComSwDangerReportVO> iPage = comSwDangerReportDAO.pageDangerReport(page, comSwPatrolRecordPageDTO);
        if (!iPage.getRecords().isEmpty()) {
            iPage.getRecords().forEach(comSwDangerReportVO -> {
                if (StringUtils.isNotEmpty(comSwDangerReportVO.getAssignPerson())) {
                    comSwDangerReportVO.setIsAssign(ComSwDangerReportVO.isOk.no);
                }else {
                    comSwDangerReportVO.setIsAssign(ComSwDangerReportVO.isOk.yes);
                }
                List<String> patrolUserIds = Arrays.asList(comSwDangerReportVO.getPatrolPerson().split(","));
                List<String> patrolPhones = new ArrayList<>();
                for (String userId : patrolUserIds) {
                    LoginUserInfoVO loginUserInfoVO = userService.getUserInfoByUserId(userId).getData();
                    patrolPhones.add(loginUserInfoVO.getPhone());
                }
                comSwDangerReportVO.setPatrolPersonPhone(StringUtils.join(patrolPhones,","));
 
                List<String> rectifyUserIds = Arrays.asList(comSwDangerReportVO.getRectifyPerson().split(","));
                List<String> rectifyPhones = new ArrayList<>();
                for (String userId : rectifyUserIds) {
                    LoginUserInfoVO loginUserInfoVO = userService.getUserInfoByUserId(userId).getData();
                    rectifyPhones.add(loginUserInfoVO.getPhone());
                }
                comSwDangerReportVO.setRectifyPersonPhone(StringUtils.join(rectifyPhones,","));
            });
        }
        return R.ok(iPage);
    }
 
    @Override
    public R detailDangerReport(Long dangerReportId) {
        ComSwDangerReportDO comSwDangerReportDO = comSwDangerReportDAO.selectById(dangerReportId);
        if (null == comSwDangerReportDO) {
            return R.fail("该隐患报告不存在");
        }
        ComSwDangerReportVO comSwDangerReportVO = new ComSwDangerReportVO();
        ComSwPatrolRecordReportDO comSwPatrolRecordReportDO = comSwPatrolRecordReportDAO.selectOne(new QueryWrapper<ComSwPatrolRecordReportDO>().lambda().eq(ComSwPatrolRecordReportDO::getReportId, dangerReportId));
        if (null != comSwPatrolRecordReportDO) {
            ComSwPatrolRecordDO comSwPatrolRecordDO = comSwPatrolRecordDAO.selectById(comSwPatrolRecordReportDO.getPatrolRecordId());
            BeanUtils.copyProperties(comSwPatrolRecordDO, comSwDangerReportVO);
        }
        BeanUtils.copyProperties(comSwDangerReportDO, comSwDangerReportVO);
        return R.ok(comSwDangerReportVO);
    }
 
    @Override
    public R detailDangerReportByPrId(Long patrolRecordId) {
        ComSwPatrolRecordDO comSwPatrolRecordDO = comSwPatrolRecordDAO.selectById(patrolRecordId);
        ComSwDangerReportVO comSwDangerReportVO = new ComSwDangerReportVO();
        ComSwPatrolRecordReportDO comSwPatrolRecordReportDO = comSwPatrolRecordReportDAO.selectOne(new QueryWrapper<ComSwPatrolRecordReportDO>().lambda().eq(ComSwPatrolRecordReportDO::getPatrolRecordId, patrolRecordId));
        if (null != comSwPatrolRecordReportDO) {
            ComSwDangerReportDO comSwDangerReportDO = comSwDangerReportDAO.selectById(comSwPatrolRecordReportDO.getReportId());
            if (null == comSwDangerReportDO) {
                return R.fail("该隐患报告不存在");
            }
            BeanUtils.copyProperties(comSwDangerReportDO, comSwDangerReportVO);
        }
        BeanUtils.copyProperties(comSwPatrolRecordDO, comSwDangerReportVO);
        return R.ok(comSwDangerReportVO);
    }
 
    @Override
    public R handleDangerReport(ComSwDangerReportHandleDTO comSwDangerReportHandleDTO) {
        ComSwDangerReportDO comSwDangerReportDO = comSwDangerReportDAO.selectById(comSwDangerReportHandleDTO.getDangerReportId());
        if (null == comSwDangerReportDO) {
            return R.fail("该隐患报告不存在");
        }
        BeanUtils.copyProperties(comSwDangerReportHandleDTO, comSwDangerReportDO);
        comSwDangerReportDO.setStatus(String.valueOf(SafeWordStatusEnum.YCL.getCode()));
        int update = comSwDangerReportDAO.updateById(comSwDangerReportDO);
        if (update > 0) {
            return R.ok();
        }
        return R.fail("处理失败");
    }
 
    @Override
    public R rectifyDangerReport(ComSwDangerReportRectifyDTO comSwDangerReportRectifyDTO) {
        ComSwDangerReportDO comSwDangerReportDO = comSwDangerReportDAO.selectById(comSwDangerReportRectifyDTO.getDangerReportId());
        if (null == comSwDangerReportDO) {
            return R.fail("该隐患报告不存在");
        }
        BeanUtils.copyProperties(comSwDangerReportRectifyDTO, comSwDangerReportDO);
        comSwDangerReportDO.setStatus(String.valueOf(SafeWordStatusEnum.YZG.getCode()));
        int update = comSwDangerReportDAO.updateById(comSwDangerReportDO);
        if (update > 0) {
            return R.ok();
        }
        return R.fail("整改失败");
    }
 
    @Override
    public R exportDangerReport(List<Long> dangerReportIds) {
        List<ComSwDangerReportExcelVO> list = comSwDangerReportDAO.exportDangerReport(dangerReportIds);
        list.forEach(comSwDangerReportExcelVO -> {
            List<String> patrolUserIds = Arrays.asList(comSwDangerReportExcelVO.getPatrolPerson().split(","));
            List<String> patrolPhones = new ArrayList<>();
            for (String userId : patrolUserIds) {
                LoginUserInfoVO loginUserInfoVO = userService.getUserInfoByUserId(userId).getData();
                patrolPhones.add(loginUserInfoVO.getPhone());
            }
            comSwDangerReportExcelVO.setPatrolPersonPhone(StringUtils.join(patrolPhones,","));
        });
        return R.ok(list);
    }
}