zhanghl
2025-05-23 dec8951aae400e54f6ee83a8f95867dba9da8af1
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package com.aps.core.service.impl;
 
import com.aps.common.core.utils.DateUtils;
import com.aps.common.security.utils.SecurityUtils;
import com.aps.core.domain.ApsGasPipelineCapacityPlan;
import com.aps.core.mapper.ApsGasPipelineCapacityPlanMapper;
import com.aps.core.service.IApsGasPipelineCapacityPlanService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
/**
 * 气体管路产能规划Service业务层处理
 *
 * @author hjy
 * @date 2025-04-24
 */
@Service
public class ApsGasPipelineCapacityPlanServiceImpl implements IApsGasPipelineCapacityPlanService {
    @Autowired
    private ApsGasPipelineCapacityPlanMapper apsGasPipelineCapacityPlanMapper;
 
    /**
     * 查询气体管路产能规划
     *
     * @param id 气体管路产能规划主键
     * @return 气体管路产能规划
     */
    @Override
    public ApsGasPipelineCapacityPlan selectApsGasPipelineCapacityPlanById(Long id) {
        return apsGasPipelineCapacityPlanMapper.selectApsGasPipelineCapacityPlanById(id);
    }
 
    /**
     * 查询气体管路产能规划列表
     *
     * @param apsGasPipelineCapacityPlan 气体管路产能规划
     * @return 气体管路产能规划
     */
    @Override
    public List<ApsGasPipelineCapacityPlan> selectApsGasPipelineCapacityPlanList(ApsGasPipelineCapacityPlan apsGasPipelineCapacityPlan) {
        return apsGasPipelineCapacityPlanMapper.selectApsGasPipelineCapacityPlanList(apsGasPipelineCapacityPlan);
    }
 
    /**
     * 新增气体管路产能规划
     *
     * @param apsGasPipelineCapacityPlan 气体管路产能规划
     * @return 结果
     */
    @Override
    public int insertApsGasPipelineCapacityPlan(ApsGasPipelineCapacityPlan apsGasPipelineCapacityPlan) {
        apsGasPipelineCapacityPlan.setCreateTime(DateUtils.getNowDate());
        apsGasPipelineCapacityPlan.setCreateBy(SecurityUtils.getUsername());
        return apsGasPipelineCapacityPlanMapper.insertApsGasPipelineCapacityPlan(apsGasPipelineCapacityPlan);
    }
 
    /**
     * 修改气体管路产能规划
     *
     * @param apsGasPipelineCapacityPlan 气体管路产能规划
     * @return 结果
     */
    @Override
    public int updateApsGasPipelineCapacityPlan(ApsGasPipelineCapacityPlan apsGasPipelineCapacityPlan) {
        apsGasPipelineCapacityPlan.setUpdateTime(DateUtils.getNowDate());
        apsGasPipelineCapacityPlan.setUpdateBy(SecurityUtils.getUsername());
        return apsGasPipelineCapacityPlanMapper.updateApsGasPipelineCapacityPlan(apsGasPipelineCapacityPlan);
    }
 
    /**
     * 批量删除气体管路产能规划
     *
     * @param ids 需要删除的气体管路产能规划主键
     * @return 结果
     */
    @Override
    public int deleteApsGasPipelineCapacityPlanByIds(Long[] ids) {
        return apsGasPipelineCapacityPlanMapper.deleteApsGasPipelineCapacityPlanByIds(ids);
    }
 
    /**
     * 删除气体管路产能规划信息
     *
     * @param id 气体管路产能规划主键
     * @return 结果
     */
    @Override
    public int deleteApsGasPipelineCapacityPlanById(Long id) {
        return apsGasPipelineCapacityPlanMapper.deleteApsGasPipelineCapacityPlanById(id);
    }
 
    @SneakyThrows
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void copyPlan(String date, String factory, String major, String toStart, String toEnd) {
 
        String[] dtSrc = date.split("-");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Calendar dtStart = Calendar.getInstance();
        dtStart.setTime(sdf.parse(toStart));
        dtStart.set(Calendar.DAY_OF_MONTH, 1);
        Calendar dtEnd = Calendar.getInstance();
        dtEnd.setTime(sdf.parse(toEnd));
        dtEnd.set(Calendar.DAY_OF_MONTH, 2);
 
        ApsGasPipelineCapacityPlan plan = new ApsGasPipelineCapacityPlan();
        plan.setYear(Integer.valueOf(dtSrc[0]).toString());
        plan.setMonth(Integer.valueOf(dtSrc[1]).toString());
        plan.setOrgCode(factory);
        plan.setMajor(major);
        List<ApsGasPipelineCapacityPlan> templatePlans = apsGasPipelineCapacityPlanMapper.selectApsGasPipelineCapacityPlanList(plan);
        templatePlans.forEach(p -> {
            p.setCreateBy(SecurityUtils.getUsername());
            p.setCreateTime(new Date());
            p.setUpdateBy(null);
            p.setUpdateTime(null);
//                apsGasPipelineCapacityPlanMapper.insertApsGasPipelineCapacityPlan(p);
        });
 
        while (dtStart.before(dtEnd)) {
            String year = dtStart.get(Calendar.YEAR) + "";
            String month = (dtStart.get(Calendar.MONTH) + 1) + "";
            apsGasPipelineCapacityPlanMapper.deleteByDateAndFactory(
                    year,
                    month,
                    factory,
                    major
            );
            templatePlans.forEach(p -> {
                p.setId(null);
                p.setYear(year);
                p.setMonth(month);
//                apsGasPipelineCapacityPlanMapper.insertApsGasPipelineCapacityPlan(p);
            });
            apsGasPipelineCapacityPlanMapper.insert(templatePlans);
 
            dtStart.add(Calendar.MONTH, 1);
        }
 
    }
}