yangys
2024-02-02 b82c71a3e3a97a78bd18ff598d27f3062600d22a
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
package com.qianwen.mdc.service.workshop;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
import org.apache.tomcat.util.buf.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianwen.mdc.domain.Section;
import com.qianwen.mdc.domain.workshop.Workshop;
import com.qianwen.mdc.domain.workshop.WorkshopAssembler;
import com.qianwen.mdc.dto.workshop.WorkshopDTO;
import com.qianwen.mdc.dto.workshop.WorkshopFullDTO;
import com.qianwen.mdc.dto.workshop.WorkshopQueryDTO;
import com.qianwen.mdc.mapper.SectionMapper;
import com.qianwen.mdc.mapper.WorkshopMapper;
 
/**
 * @author y_ys79
 * 车间服务,提供增删改查全部操作(逻辑比较简单)
 */
@Service
public class WorkshopService {
    @Autowired
    private WorkshopMapper workshopMapper;
    @Autowired
    private SectionMapper sectionMapper;
    
 
    /**
     * 获取车间列表,附带车间下的工段数据
     * @return
     */
    @Transactional(readOnly=true)
    public List<WorkshopDTO> listWithSections() {
        List<Workshop> list = workshopMapper.selectList(Wrappers.emptyWrapper());
        return list.stream().map(ws -> {
            List<Section> sectionList = sectionMapper.queryByWorkshopId(ws.getId());
            WorkshopDTO wsDTO = WorkshopAssembler.toDTO(ws,sectionList);
            
            return wsDTO;
            }).collect(Collectors.toList());
    }
 
    @Transactional(readOnly=true)
    public Page<WorkshopFullDTO> pageQuery(WorkshopQueryDTO dto) {
        Page<WorkshopFullDTO> rowPage = new Page<>(dto.finalPageNo(),dto.finalPageSize());
        rowPage = workshopMapper.queryPage(rowPage, dto);
        
        rowPage.getRecords().forEach((ws) -> {
            List<Section> sectionList = sectionMapper.queryByWorkshopId(ws.getId());
            List<String> nameList = new ArrayList<>();
            for(Section s : sectionList) {
                nameList.add(s.getName());
            }
            
            ws.setSectionNames(StringUtils.join(nameList,','));
        });
    
        return rowPage;
    }
}