package com.yuanchu.mom.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.yuanchu.mom.mapper.DeviceMapper;
|
import com.yuanchu.mom.mapper.ManualTechnologyMapper;
|
import com.yuanchu.mom.mapper.ManufactureOrderMapper;
|
import com.yuanchu.mom.pojo.ManualTechnology;
|
import com.yuanchu.mom.pojo.ManufactureOrder;
|
import com.yuanchu.mom.pojo.Technology;
|
import com.yuanchu.mom.pojo.dto.ManualTechnologyDto;
|
import com.yuanchu.mom.service.ManualTechnologyService;
|
import com.yuanchu.mom.service.TechnologyService;
|
import com.yuanchu.mom.utils.MyUtil;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.text.DateFormat;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 编制工序表(ManualTechnology)表服务实现类
|
*
|
* @author zss
|
* @since 2023-08-17 14:16:46
|
*/
|
@Service
|
public class ManualTechnologyServiceImpl extends ServiceImpl<ManualTechnologyMapper, ManualTechnology> implements ManualTechnologyService {
|
|
@Resource
|
ManualTechnologyMapper manualTechnologyMapper;
|
|
@Resource
|
ManufactureOrderMapper manufactureOrderMapper;
|
|
@Autowired
|
private TechnologyService technologyService;
|
|
//排产-->查看
|
@Override
|
public List<Map<String, Object>> seleDatil(Integer manOrdId) {
|
|
return manualTechnologyMapper.seleDatil(manOrdId);
|
}
|
|
//排产-->更新
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void output(String date, Integer manufactureOrderId, Integer schedulingNumber, List<ManualTechnologyDto> manualTechnologyDtoList) throws ParseException {
|
// 查询工艺,用于匹配每个订单的工序周期
|
LambdaQueryWrapper<Technology> wrapper = new LambdaQueryWrapper<>();
|
wrapper.select(Technology::getId, Technology::getProductionQuota);
|
List<Technology> technologies = technologyService.list(wrapper);
|
|
|
//匹配每个订单的工序周期
|
List<ManualTechnology> manualTechnologies = manualTechnologyDtoList.stream().map(manualTechnologyDto -> {
|
ManualTechnology manualTechnology = new ManualTechnology();
|
BeanUtils.copyProperties(manualTechnologyDto, manualTechnology);
|
technologies.forEach(i -> {
|
if (Objects.equals(manualTechnology.getTechnologyId(), i.getId())){
|
manualTechnology.setPeriod((int) Math.ceil((double)schedulingNumber/i.getProductionQuota()));
|
}
|
});
|
return manualTechnology;
|
}).collect(Collectors.toList());
|
|
|
// 计算工序的开始日期以及结束日期
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
Date parse = dateFormat.parse(date);
|
//将起始日期赋值给Calendar对象
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(parse);
|
//第一个工序
|
ManualTechnology manualTechnology = manualTechnologies.get(0);
|
calendar.add(Calendar.DATE, manualTechnology.getPeriod());
|
|
|
manualTechnology.setStartTime(parse).setEndTime(calendar.getTime());
|
//循环赋值时间
|
for (int i = 0; i < manualTechnologies.size()-1 ; i++) {
|
Calendar calendar1 = Calendar.getInstance();
|
calendar1.setTime(manualTechnologies.get(i).getEndTime());
|
ManualTechnology technology = manualTechnologies.get(i + 1);
|
calendar1.add(Calendar.DATE,1);
|
technology.setStartTime(calendar1.getTime());
|
calendar1.add(Calendar.DATE,technology.getPeriod());
|
technology.setEndTime(calendar1.getTime());
|
}
|
|
|
// 数据处理完成开始批量更新Mysql
|
manualTechnologyMapper.updateBatchManualTechnology(schedulingNumber, manualTechnologies);
|
|
|
// 工序更新完毕,更新订单的状态,将其更新为已排产:1,还有待下达:0
|
manufactureOrderMapper.updateManufacture(manufactureOrderId, schedulingNumber);
|
}
|
}
|