kongzy
2024-03-15 50c669c09a7b392af22706e6fb1fa8a4c335d8eb
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
package com.gkhy.assess.system.service.impl;
 
import com.gkhy.assess.common.enums.RequestSourceEnum;
import com.gkhy.assess.common.exception.ApiException;
import com.gkhy.assess.system.domain.AssInvestigation;
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;
 
/**
 * <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 int addInvestigation(AssInvestigation investigation,String requestSourceType) {
        Long projectId=investigation.getProjectId();
        projectService.checkUserAllowed(projectId);
        checkInvestigationCount(projectId);
        investigation.setCreateBy(ShiroUtils.getSysUser().getUsername());
        if(investigation.getIsSafetyCheck()!=null&&investigation.getIsSafetyCheck()==1){
            Integer fileCount=accessoryFileService.getAccessoryFileCountByProjectId(projectId, AccessoryFileTypeEnum.INVESTINGATION_ATTACHMENT.getCode());
            if(fileCount==0){
                throw new ApiException("未上传现场安全检查表");
            }
        }
        //校验图片数量
        Integer fileCount=accessoryFileService.getAccessoryFileCountByProjectId(projectId, AccessoryFileTypeEnum.DEVICE_IMAGE.getCode());
        if(fileCount==0){
            throw new ApiException("主要装置前的合影照片不能为空");
        }
        fileCount=accessoryFileService.getAccessoryFileCountByProjectId(projectId, AccessoryFileTypeEnum.INVESTINGATION_IMAGE.getCode());
        if(fileCount==0){
            throw new ApiException("现场勘验照片照片不能为空");
        }
        fileCount=accessoryFileService.getAccessoryFileCountByProjectId(projectId, AccessoryFileTypeEnum.COMPANY_IMAGE.getCode());
        if(fileCount==0){
            throw new ApiException("现场勘验人员与企业陪同人员图片不能为空");
        }
//        fileCount=accessoryFileService.getAccessoryFileCountByProjectId(projectId, AccessoryFileTypeEnum.INVESTINGATION_VIDEO.getCode());
//        if(fileCount==0){
//            throw new ApiException("现场勘验视频不能为空");
//        }
        int row=baseMapper.insert(investigation);
        if(requestSourceType== RequestSourceEnum.WEB.getCode()){
            //校验项目状态
            projectService.checkReportProgress(projectId, ReportProgressEnum.WORK_NOTIFICATION);
            //更新项目状态
            projectService.changeReportProgress(projectId,ReportProgressEnum.INVESTINGATION);
        }
        //校验项目状态
//        projectService.checkReportProgress(projectId, ReportProgressEnum.WORK_NOTIFICATION);
//        int row=baseMapper.insert(investigation);
//        if(row>0 && (investigation.getState()==null||!investigation.getState().equals(ApproveStatusEnum.TEMPORARY.getCode()))) {
//            //更新项目状态
//            projectService.changeReportProgress(projectId,ReportProgressEnum.INVESTINGATION);
//        }
        return row;
    }
 
    public void checkInvestigationCount(Long projectId){
        //校验项目下勘验记录数量
        int count= baseMapper.getCountByProjectId(projectId);
        if(count>0){
            throw new ApiException("项目下已存在现场勘验记录");
        }
    }
 
    @Override
    public int editInvestigation(AssInvestigation investigation) {
        projectService.checkUserAllowed(investigation.getProjectId());
        investigation.setUpdateBy(ShiroUtils.getSysUser().getUsername());
        int row=baseMapper.updateById(investigation);
        return row;
    }
 
    @Override
    public AssInvestigation getInvestigationByProjectId(Long projectId) {
        projectService.checkUserAllowed(projectId);
        AssInvestigation investigation= baseMapper.getInvestigationByProjectId(projectId);
        if(investigation!=null) {
            investigation.setAssAccessoryFiles(accessoryFileService.getAccessoryFileByProjectId(projectId, AccessoryFileTypeEnum.INVESTINGATION_ATTACHMENT.getCode()));
            investigation.setCcompanyImages(accessoryFileService.getAccessoryFileByProjectId(projectId, AccessoryFileTypeEnum.COMPANY_IMAGE.getCode()));
            investigation.setDeviceImages(accessoryFileService.getAccessoryFileByProjectId(projectId, AccessoryFileTypeEnum.DEVICE_IMAGE.getCode()));
            investigation.setInvestingationImages(accessoryFileService.getAccessoryFileByProjectId(projectId, AccessoryFileTypeEnum.INVESTINGATION_IMAGE.getCode()));
            investigation.setInvestingationVideos(accessoryFileService.getAccessoryFileByProjectId(projectId, AccessoryFileTypeEnum.INVESTINGATION_VIDEO.getCode()));
        }
        return investigation;
    }
 
 
    @Override
    public AssInvestigation getInvestigationById(Long investigationId) {
        return baseMapper.getInvestigationById(investigationId);
    }
 
    @Override
    public void doInvestigationProcess(Long projectId) {
        projectService.checkUserAllowed(projectId);
        //校验项目状态
        projectService.checkReportProgress(projectId, ReportProgressEnum.WORK_NOTIFICATION);
        //更新项目状态
        projectService.changeReportProgress(projectId,ReportProgressEnum.INVESTINGATION);
    }
}