liyong
2026-07-10 80ddf4c9c0bcb0f6c31524e0d9f5599c8001e904
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
package cn.iocoder.yudao.module.mes.service.cal.plan;
 
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.team.MesCalPlanTeamSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanTeamDO;
import cn.iocoder.yudao.module.mes.dal.mysql.cal.plan.MesCalPlanTeamMapper;
import cn.iocoder.yudao.module.mes.service.cal.team.MesCalTeamService;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
 
import java.util.List;
 
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
 
/**
 * MES 计划班组关联 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class MesCalPlanTeamServiceImpl implements MesCalPlanTeamService {
 
    @Resource
    private MesCalPlanTeamMapper planTeamMapper;
 
    @Resource
    @Lazy
    private MesCalPlanService planService;
    @Resource
    @Lazy
    private MesCalTeamService teamService;
 
    @Override
    public Long createPlanTeam(MesCalPlanTeamSaveReqVO createReqVO) {
        // 校验计划未确认
        planService.validatePlanPrepare(createReqVO.getPlanId());
        // 校验班组存在
        teamService.validateTeamExists(createReqVO.getTeamId());
        // 校验班组不重复
        validatePlanTeamDuplicate(createReqVO.getPlanId(), createReqVO.getTeamId());
 
        // 插入
        MesCalPlanTeamDO planTeam = BeanUtils.toBean(createReqVO, MesCalPlanTeamDO.class);
        planTeamMapper.insert(planTeam);
        return planTeam.getId();
    }
 
    @Override
    public void deletePlanTeam(Long id) {
        // 校验存在
        MesCalPlanTeamDO existPlanTeam = validatePlanTeamExists(id);
        // 校验计划未确认
        planService.validatePlanPrepare(existPlanTeam.getPlanId());
        // 删除
        planTeamMapper.deleteById(id);
    }
 
    private MesCalPlanTeamDO validatePlanTeamExists(Long id) {
        MesCalPlanTeamDO planTeam = planTeamMapper.selectById(id);
        if (planTeam == null) {
            throw exception(CAL_PLAN_TEAM_NOT_EXISTS);
        }
        return planTeam;
    }
 
    private void validatePlanTeamDuplicate(Long planId, Long teamId) {
        MesCalPlanTeamDO planTeam = planTeamMapper.selectByPlanIdAndTeamId(planId, teamId);
        if (planTeam != null) {
            throw exception(CAL_PLAN_TEAM_DUPLICATE);
        }
    }
 
    @Override
    public List<MesCalPlanTeamDO> getPlanTeamListByPlanId(Long planId) {
        return planTeamMapper.selectListByPlanId(planId);
    }
 
    @Override
    public Long getPlanTeamCountByPlanId(Long planId) {
        return planTeamMapper.selectCountByPlanId(planId);
    }
 
    @Override
    public void deleteByPlanId(Long planId) {
        planTeamMapper.deleteByPlanId(planId);
    }
 
}