XiaoRuby
2023-08-30 55e5fcc8df938fefc94103149dfe3acd328abfd6
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
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);
    }
}