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
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.AssEstimatePlan;
import com.gkhy.assess.system.domain.AssEstimateSchedule;
import com.gkhy.assess.system.domain.AssPlanPerson;
import com.gkhy.assess.system.enums.PlayRoleEnum;
import com.gkhy.assess.system.enums.ReportProgressEnum;
import com.gkhy.assess.system.mapper.AssEstimatePlanMapper;
import com.gkhy.assess.system.service.*;
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.List;
 
/**
 * <p>
 * 评价项目计划表 服务实现类
 * </p>
 *
 * @author kzy
 * @since 2023-12-12 10:46:54
 */
@Service
public class AssEstimatePlanServiceImpl extends ServiceImpl<AssEstimatePlanMapper, AssEstimatePlan> implements AssEstimatePlanService {
    @Autowired
    private AssProjectService projectService;
 
    @Autowired
    private AssEstimateScheduleService estimateScheduleService;
 
    @Autowired
    private AssPlanPersonService planPersonService;
 
    @Autowired
    private AssDeviceService deviceService;
 
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int addEstimatePlan(AssEstimatePlan estimatePlan) {
        Long projectId=estimatePlan.getProjectId();
        projectService.checkUserAllowed(projectId);
        checkEstimatePlanCount(projectId);
        planPersonService.checkPersonUnique(new AssPlanPerson().setPersonId(estimatePlan.getAuserId()).setProjectId(projectId));
        //校验项目状态
        projectService.checkReportProgress(projectId, ReportProgressEnum.ESTIMATE_TASK);
        estimatePlan.setCreateBy(ShiroUtils.getSysUser().getUsername());
        int row=baseMapper.insert(estimatePlan);
        if(row>0) {
            //更新项目状态
            projectService.changeReportProgress(projectId,ReportProgressEnum.ESTIMATE_PLAN);
            //todo 机构负责人
            planPersonService.addPlanPerson(new AssPlanPerson().setPersonId(estimatePlan.getAuserId())
                    .setPlayRole(PlayRoleEnum.ANGENCY_LEADER.getCode())
                    .setProjectId(projectId));
        }
        //todo 新增评价日程安排
        estimateScheduleService.saveBatch(estimatePlan.getEstimateSchedules());
        return row;
    }
 
    public void checkEstimatePlanCount(Long projectId){
        //校验项目下评价计划数量
        int contractCount= baseMapper.getCountByProjectId(projectId);
        if(contractCount>0){
            throw new ApiException("项目下已存在评价计划信息");
        }
    }
 
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int editEstimatePlan(AssEstimatePlan estimatePlan) {
        projectService.checkUserAllowed(estimatePlan.getProjectId());
        AssEstimatePlan oldPlan=getById(estimatePlan.getId());
        estimatePlan.setUpdateBy(ShiroUtils.getSysUser().getUsername());
        int row=baseMapper.updateById(estimatePlan);
        List<AssEstimateSchedule> estimateScheduleList=estimatePlan.getEstimateSchedules();
        if(estimateScheduleList!=null&&estimateScheduleList.size()>0){
            estimateScheduleService.updateBatchById(estimateScheduleList);
        }
        if(row>0) {
            if (estimatePlan.getAuserId() != null && !estimatePlan.getAuserId().equals(oldPlan.getAuserId())) {
                planPersonService.checkPersonUnique(new AssPlanPerson().setPersonId(estimatePlan.getAuserId()).setProjectId(oldPlan.getProjectId()));
                //todo 删除旧的项目成员
                planPersonService.deletePlanPersonByPersonId(oldPlan.getAuserId());
                //todo 新增新的项目成员
                planPersonService.addPlanPerson(new AssPlanPerson().setPersonId(estimatePlan.getAuserId())
                        .setPlayRole(PlayRoleEnum.ANGENCY_LEADER.getCode())
                        .setProjectId(oldPlan.getProjectId()));
            }
        }
        return row;
    }
 
    @Override
    public AssEstimatePlan getEstimatePlanByProjectId(Long projectId) {
        projectService.checkUserAllowed(projectId);
        AssEstimatePlan assEstimatePlan= baseMapper.getEstimatePlanByProjectId(projectId);
        assEstimatePlan.setPlanPersons(planPersonService.getByProjectId(projectId));
        assEstimatePlan.setEstimateSchedules(estimateScheduleService.getByProjectId(projectId));
        assEstimatePlan.setDevices(deviceService.getByProjectId(projectId));
        return assEstimatePlan;
    }
 
 
    @Override
    public AssEstimatePlan getEstimatePlanById(Long estimatePlanId) {
        AssEstimatePlan estimatePlan= baseMapper.getEstimatePlanById(estimatePlanId);
        projectService.checkUserAllowed(estimatePlan.getProjectId());
        return estimatePlan;
    }
}