yangys
2024-12-30 7cd413d0f1e3235223848d47e428aad97f9f13fc
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
package com.qianwen.smartman.modules.workinghour.service;
 
import java.time.Duration;
import java.util.List;
import java.util.stream.Collectors;
 
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.oss.model.BladeFile;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.smartman.common.enums.DefaultWcsEnum;
import com.qianwen.smartman.common.utils.DurationUtil;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
import com.qianwen.smartman.modules.smis.entity.Workstation;
import com.qianwen.smartman.modules.smis.excel.WorkstationExcel;
import com.qianwen.smartman.modules.smis.mapper.WorkstationMapper;
import com.qianwen.smartman.modules.workinghour.convert.PartWorkingProcessConvert;
import com.qianwen.smartman.modules.workinghour.entity.PartWorkingHour;
import com.qianwen.smartman.modules.workinghour.entity.PartWorkingProcess;
import com.qianwen.smartman.modules.workinghour.excel.PartWorkingProcessExcel;
import com.qianwen.smartman.modules.workinghour.mapper.PartWorkingHourMapper;
import com.qianwen.smartman.modules.workinghour.mapper.PartWorkingProcessMapper;
import com.qianwen.smartman.modules.workinghour.vo.PartWorkingProcessVO;
 
@Service
public class PartWorkingProcessService{
 
    @Autowired
    private PartWorkingProcessMapper partWorkingProcessMapper;
    @Autowired
    private WorkstationMapper workstationMapper;
    @Autowired
    private PartWorkingHourMapper partWorkingHourMapper;
    @Autowired
    private OssBuilder ossBuilder;
 
 
    @Transactional(readOnly=true)
    public List<PartWorkingProcessVO> listByWorkinghourId(Long workinghourId) {
        QueryWrapper<PartWorkingProcess> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(PartWorkingProcess::getWorkinghourId, workinghourId).orderByAsc(PartWorkingProcess::getStartTime);
        
        return PartWorkingProcessConvert.INSTANCE.convert(partWorkingProcessMapper.selectList(wrapper));
    }
 
    /**
     * 加工过程数据导出
     * @param id
     * @return
     */
    @Transactional(readOnly=true)
    public BladeFile export(long workinghourId) {
        QueryWrapper<PartWorkingProcess> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(PartWorkingProcess::getWorkinghourId, workinghourId).orderByAsc(PartWorkingProcess::getStartTime);
        List<PartWorkingProcess> data = partWorkingProcessMapper.selectList(wrapper);
        List<PartWorkingProcessExcel> exportList = data.stream().map(p -> {
            PartWorkingProcessExcel e = new PartWorkingProcessExcel();
            e.setProgName(p.getProgName());
            e.setStartTime(p.getStartTime().toString());
            e.setEndTime(p.getEndTime().toString());
            
            Duration duration = Duration.between(p.getStartTime(), p.getEndTime());
            e.setDuration(DurationUtil.toChineseDuration(duration));
            e.setDeviceStateName(DefaultWcsEnum.of(p.getDeviceStatus()).getName());
            return e;
        }).collect(Collectors.toList());
        //xx工件在x机床
        PartWorkingHour partWorkingHour = partWorkingHourMapper.selectById(workinghourId);
        Workstation ws = workstationMapper.selectById(partWorkingHour.getWorkstationId());
        String fileName = String.format("%s的加工记录-%s.xlsx", ws.getName(), DateUtil.time());
        MultipartFile multipartFile = ExcelUtil.exportToMultipartFile(fileName, "加工记录表", exportList, PartWorkingProcessExcel.class);
        BladeFile bladeFile = this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
        return bladeFile;
    }
    
    
 
}