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);
|
}
|
|
}
|
}
|