sfd
2025-05-19 930780a650df99ccf1e6e48ee3a2242a1af22746
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
package com.aps.core.service.impl;
 
import cn.hutool.core.util.IdUtil;
import com.aps.common.core.utils.DateUtils;
import com.aps.common.security.utils.SecurityUtils;
import com.aps.core.domain.ApsPlanCycle;
import com.aps.core.domain.ApsPlanManagement;
import com.aps.core.mapper.ApsPlanCycleMapper;
import com.aps.core.mapper.ApsPlanManagementMapper;
import com.aps.core.service.IApsPlanManagementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
import java.util.Objects;
 
/**
 * 计划管理Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-13
 */
@Service
public class ApsPlanManagementServiceImpl extends ServiceImpl<ApsPlanManagementMapper, ApsPlanManagement> implements IApsPlanManagementService {
    @Autowired
    private ApsPlanManagementMapper apsPlanManagementMapper;
 
    @Autowired
    private ApsPlanCycleMapper apsPlanCycleMapper;
 
    /**
     * 查询计划管理
     *
     * @param id 计划管理主键
     * @return 计划管理
     */
    @Override
    public ApsPlanManagement selectApsPlanManagementById(Long id) {
        return selectApsPlanManagementById(id);
    }
 
    /**
     * 查询计划管理列表
     *
     * @param apsPlanManagement 计划管理
     * @return 计划管理
     */
    @Override
    public List<ApsPlanManagement> selectApsPlanManagementList(ApsPlanManagement apsPlanManagement) {
        List<ApsPlanManagement> items = apsPlanManagementMapper.selectApsPlanManagementList(apsPlanManagement);
        List<ApsPlanCycle> cycles = apsPlanCycleMapper.selectByPlanIds(items.stream().map(ApsPlanManagement::getId).toList());
        cycles.forEach(cycle -> {
            for (ApsPlanManagement item : items) {
                if (Objects.equals(item.getId(), cycle.getPlanId())) {
                    item.setCycle(cycle);
                    break;
                }
            }
        });
        return items;
    }
 
    /**
     * 新增计划管理
     *
     * @param apsPlanManagement 计划管理
     * @return 结果
     */
    @Override
    public int insertApsPlanManagement(ApsPlanManagement apsPlanManagement) {
        apsPlanManagement.setCreateTime(DateUtils.getNowDate());
        apsPlanManagement.setCreateBy(SecurityUtils.getUsername());
        apsPlanManagement.setId(IdUtil.getSnowflakeNextId());
        return apsPlanManagementMapper.insertApsPlanManagement(apsPlanManagement);
    }
 
    /**
     * 修改计划管理
     *
     * @param apsPlanManagement 计划管理
     * @return 结果
     */
    @Override
    public int updateApsPlanManagement(ApsPlanManagement apsPlanManagement) {
        apsPlanManagement.setUpdateTime(DateUtils.getNowDate());
        apsPlanManagement.setUpdateBy(SecurityUtils.getUsername());
        return apsPlanManagementMapper.updateApsPlanManagement(apsPlanManagement);
    }
 
    /**
     * 批量删除计划管理
     *
     * @param ids 需要删除的计划管理主键
     * @return 结果
     */
    @Override
    public int deleteApsPlanManagementByIds(Long[] ids) {
        return apsPlanManagementMapper.deleteApsPlanManagementByIds(ids);
    }
 
    /**
     * 删除计划管理信息
     *
     * @param id 计划管理主键
     * @return 结果
     */
    @Override
    public int deleteApsPlanManagementById(Long id) {
        return apsPlanManagementMapper.deleteApsPlanManagementById(id);
    }
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateApsPlanCycle(ApsPlanCycle apsPlanCycle) {
        ApsPlanCycle planCycle = apsPlanCycleMapper.selectByPlanId(apsPlanCycle.getPlanId());
        if (planCycle == null) {
            apsPlanCycle.setCreateBy(SecurityUtils.getUsername());
            apsPlanCycle.setCreateTime(DateUtils.getNowDate());
            apsPlanCycle.setId(IdUtil.getSnowflakeNextId());
            apsPlanCycleMapper.insert(apsPlanCycle);
        } else {
            BeanUtils.copyProperties(apsPlanCycle, planCycle, "id", "planId");
            planCycle.setUpdateBy(SecurityUtils.getUsername());
            planCycle.setUpdateTime(DateUtils.getNowDate());
            apsPlanCycleMapper.updateById(planCycle);
        }
    }
}