kongzy
2024-07-12 28aaf2ffa1dbb860a292ba330a7e9362e60e7832
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
package com.gkhy.assess.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gkhy.assess.common.enums.DeleteFlagEnum;
import com.gkhy.assess.common.enums.RequestSourceEnum;
import com.gkhy.assess.common.exception.ApiException;
import com.gkhy.assess.system.domain.AssAccessoryFile;
import com.gkhy.assess.system.domain.AssInvestigation;
import com.gkhy.assess.system.domain.AssPlanPerson;
import com.gkhy.assess.system.enums.AccessoryFileTypeEnum;
import com.gkhy.assess.system.enums.ReportProgressEnum;
import com.gkhy.assess.system.mapper.AssInvestigationMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.assess.system.service.AssAccessoryFileService;
import com.gkhy.assess.system.service.AssInvestigationService;
import com.gkhy.assess.system.service.AssProjectService;
import com.gkhy.assess.system.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 现场勘验记录表 服务实现类
 * </p>
 *
 * @author kzy
 * @since 2023-12-12 10:46:54
 */
@Service
public class AssInvestigationServiceImpl extends ServiceImpl<AssInvestigationMapper, AssInvestigation> implements AssInvestigationService {
 
    @Autowired
    private AssProjectService projectService;
 
    @Autowired
    private AssAccessoryFileService accessoryFileService;
 
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public Long addInvestigation(AssInvestigation investigation) {
        Long projectId=investigation.getProjectId();
        projectService.checkUserAllowed(projectId);
        String location=investigation.getLocation();
        String[] locationArray = location.split(",");
        if(locationArray.length!=2){
            throw new ApiException("现场勘验位置格式不正确");
        }
     //   checkInvestigationCount(projectId);
        investigation.setCreateBy(ShiroUtils.getSysUser().getUsername());
        if(investigation.getIsSafetyCheck()!=null&&investigation.getIsSafetyCheck()==1){
            Integer fileCount=accessoryFileService.getAccessoryFileCountByProjectId(projectId,null, AccessoryFileTypeEnum.INVESTINGATION_ATTACHMENT.getCode());
            if(fileCount==0){
                throw new ApiException("未上传现场安全检查表");
            }
        }
        List<AssAccessoryFile> accessFiles=new ArrayList<>();
        accessFiles.addAll(investigation.getCompanyImages());
        accessFiles.addAll(investigation.getDeviceImages());
        accessFiles.addAll(investigation.getInvestingationImages());
        if(investigation.getInvestingationVideos()!=null&& !investigation.getInvestingationVideos().isEmpty()){
            accessFiles.addAll(investigation.getInvestingationVideos());
        }
        if(investigation.getAssAccessoryFiles()!=null&&!investigation.getAssAccessoryFiles().isEmpty()){
            accessFiles.addAll(investigation.getAssAccessoryFiles());
        }
        List<Long> fileIds=new ArrayList<>();
        for(AssAccessoryFile accessoryFile:accessFiles){
            if(accessoryFile.getId()==null){
                throw new ApiException("附件或图片id不能为空");
            }
            fileIds.add(accessoryFile.getId());
        }
 
        baseMapper.insert(investigation);
        //更新图片过程id
        accessoryFileService.batchUpdateAccessoryFileProcessId(fileIds,investigation.getId());
        return investigation.getId();
    }
 
    public void checkInvestigationCount(Long projectId){
        //校验项目下勘验记录数量
        int count= baseMapper.getCountByProjectId(projectId);
        if(count>0){
            throw new ApiException("项目下已存在现场勘验记录");
        }
    }
 
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int editInvestigation(AssInvestigation investigation) {
        if(investigation.getId()==null){
            throw new ApiException("现场勘验记录id不能为空!");
        }
        projectService.checkUserAllowed(investigation.getProjectId());
        String location=investigation.getLocation();
        String[] locationArray = location.split(",");
        if(locationArray.length!=2){
            throw new ApiException("现场勘验位置格式不正确");
        }
        investigation.setUpdateBy(ShiroUtils.getSysUser().getUsername());
        List<AssAccessoryFile> accessFiles=new ArrayList<>();
        accessFiles.addAll(investigation.getCompanyImages());
        accessFiles.addAll(investigation.getDeviceImages());
        accessFiles.addAll(investigation.getInvestingationImages());
        if(investigation.getInvestingationVideos()!=null&& !investigation.getInvestingationVideos().isEmpty()){
            accessFiles.addAll(investigation.getInvestingationVideos());
        }
        if(investigation.getAssAccessoryFiles()!=null&&!investigation.getAssAccessoryFiles().isEmpty()){
            accessFiles.addAll(investigation.getAssAccessoryFiles());
        }
        List<Long> fileIds=new ArrayList<>();
        for(AssAccessoryFile accessoryFile:accessFiles){
            if(accessoryFile.getId()==null){
                throw new ApiException("附件或图片id不能为空");
            }
            fileIds.add(accessoryFile.getId());
        }
        accessoryFileService.batchUpdateAccessoryFileProcessId(fileIds,investigation.getId());
        int row=baseMapper.updateById(investigation);
        return row;
    }
 
    @Override
    public List<AssInvestigation> getInvestigationByProjectId(Long projectId) {
        projectService.checkUserAllowed(projectId);
        List<AssInvestigation> investigations= baseMapper.getInvestigationByProjectId(projectId);
        return investigations;
    }
 
 
    @Override
    public AssInvestigation getInvestigationById(Long investigationId) {
        AssInvestigation investigation= baseMapper.getInvestigationById(investigationId);
        if(investigation!=null) {
            investigation.setAssAccessoryFiles(accessoryFileService.getAccessoryFileByProjectId(investigation.getProjectId(),investigation.getId(), AccessoryFileTypeEnum.INVESTINGATION_ATTACHMENT.getCode()));
            investigation.setCompanyImages(accessoryFileService.getAccessoryFileByProjectId(investigation.getProjectId(),investigation.getId(), AccessoryFileTypeEnum.COMPANY_IMAGE.getCode()));
            investigation.setDeviceImages(accessoryFileService.getAccessoryFileByProjectId(investigation.getProjectId(),investigation.getId(), AccessoryFileTypeEnum.DEVICE_IMAGE.getCode()));
            investigation.setInvestingationImages(accessoryFileService.getAccessoryFileByProjectId(investigation.getProjectId(),investigation.getId(), AccessoryFileTypeEnum.INVESTINGATION_IMAGE.getCode()));
            investigation.setInvestingationVideos(accessoryFileService.getAccessoryFileByProjectId(investigation.getProjectId(),investigation.getId(), AccessoryFileTypeEnum.INVESTINGATION_VIDEO.getCode()));
        }
        return investigation;
    }
 
    @Override
    public void doInvestigationProcess(Map map) {
        Long projectId= Long.parseLong(map.get("projectId").toString());
        projectService.checkUserAllowed(projectId);
 
        LambdaQueryWrapper< AssInvestigation > lambdaQueryWrapper = Wrappers.<AssInvestigation>lambdaQuery()
                .eq(AssInvestigation::getProjectId, projectId)
                .eq(AssInvestigation::getDelFlag, DeleteFlagEnum.UN_DELETE);
 
        Long count= count(lambdaQueryWrapper);
        if(count<1){
            throw new ApiException("现场勘验记录不能为空");
        }
        //校验项目状态
        projectService.checkReportProgress(projectId, ReportProgressEnum.WORK_NOTIFICATION);
        //更新项目状态
        projectService.changeReportProgress(projectId,ReportProgressEnum.INVESTINGATION);
    }
}