fix
heheng
2025-01-07 d37a3ee6a7439b376b260177f3fb318a94833b5e
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
package com.gkhy.assess.system.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.assess.common.exception.ApiException;
import com.gkhy.assess.system.domain.AssProject;
import com.gkhy.assess.system.domain.AssWorkNotification;
import com.gkhy.assess.system.enums.AccessoryFileTypeEnum;
import com.gkhy.assess.system.enums.ReportProgressEnum;
import com.gkhy.assess.system.mapper.AssWorkNotificationMapper;
import com.gkhy.assess.system.service.AssAccessoryFileService;
import com.gkhy.assess.system.service.AssProjectService;
import com.gkhy.assess.system.service.AssWorkNotificationService;
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 AssWorkNotificationServiceImpl extends ServiceImpl<AssWorkNotificationMapper, AssWorkNotification> implements AssWorkNotificationService {
    @Autowired
    private AssProjectService projectService;
    @Autowired
    private AssAccessoryFileService accessoryFileService;
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int addWorkNotification(AssWorkNotification workNotification) {
        Long projectId=workNotification.getProjectId();
        projectService.checkUserAllowed(projectId);
        checkWorkNotificationCount(projectId);
        AssProject projectById = projectService.getProjectById(projectId);
        if (projectById==null){
            throw new ApiException("项目不存在");
        }
        if(projectById.getEstimateType() != 33){
            Integer fileCount=accessoryFileService.getAccessoryFileCountByProjectId(projectId,null, AccessoryFileTypeEnum.EMPLOYMENT_NOTICE.getCode());
            if(fileCount==0){
                throw new ApiException("未上传从业告知书");
            }
        }
 
        //校验项目状态
        projectService.checkReportProgress(projectId, ReportProgressEnum.ESTIMATE_PLAN);
        workNotification.setCreateBy(ShiroUtils.getSysUser().getUsername());
        int row=baseMapper.insert(workNotification);
        if(row>0) {
            //更新项目状态
            projectService.changeReportProgress(projectId,ReportProgressEnum.WORK_NOTIFICATION);
        }
        return row;
    }
 
    public void checkWorkNotificationCount(Long projectId){
        //校验项目下从业告知数量
        int count= baseMapper.getCountByProjectId(projectId);
        if(count>0){
            throw new ApiException("项目下已存在从业告知");
        }
    }
 
    @Override
    public int editWorkNotification(AssWorkNotification workNotification) {
        projectService.checkUserAllowed(workNotification.getProjectId());
        workNotification.setUpdateBy(ShiroUtils.getSysUser().getUsername());
        int row=baseMapper.updateById(workNotification);
        return row;
    }
 
    @Override
    public AssWorkNotification getWorkNotificationByProjectId(Long projectId) {
        projectService.checkUserAllowed(projectId);
        return baseMapper.getWorkNotificationByProjectId(projectId);
    }
 
    @Override
    public AssWorkNotification getWorkNotificationById(Long workNotificationId) {
        return baseMapper.getWorkNotificationById(workNotificationId);
    }
}