zss
6 天以前 51ec98113c6d49d0f7eec4e3c030e55e337e97db
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.yuanchu.mom.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
import com.deepoove.poi.data.FilePictureRenderData;
import com.yuanchu.mom.dto.InternalMeetingParticipantDto;
import com.yuanchu.mom.dto.ManageMeetingDto;
import com.yuanchu.mom.dto.ManageMeetingParticipantsDto;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.mapper.DepartmentMapper;
import com.yuanchu.mom.mapper.ManageMeetingParticipantsMapper;
import com.yuanchu.mom.mapper.UserMapper;
import com.yuanchu.mom.pojo.ManageMeeting;
import com.yuanchu.mom.mapper.ManageMeetingMapper;
import com.yuanchu.mom.pojo.ManageMeetingParticipants;
import com.yuanchu.mom.pojo.ManageReviewProgram;
import com.yuanchu.mom.pojo.User;
import com.yuanchu.mom.service.ManageMeetingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.mom.utils.HackLoopTableRenderPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.sql.Wrapper;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author
 * @since 2024-11-11 09:33:47
 */
@Service
public class ManageMeetingServiceImpl extends ServiceImpl<ManageMeetingMapper, ManageMeeting> implements ManageMeetingService {
 
 
    @Resource
    private ManageMeetingParticipantsMapper manageMeetingParticipantsMapper;
 
    @Autowired
    private UserMapper userMapper;
 
    @Override
    public IPage<ManageMeetingDto> page(Page page, String startTime, String endTime, String place) {
        IPage<ManageMeetingDto> iPage = this.baseMapper.page(page, startTime, endTime, place);
        for (ManageMeetingDto record : iPage.getRecords()) {
            List<ManageMeetingParticipants> manageMeetingParticipants = manageMeetingParticipantsMapper.selectList(Wrappers.<ManageMeetingParticipants>lambdaQuery().eq(ManageMeetingParticipants::getMeetingId, record.getId()));
            String collect = manageMeetingParticipants.stream().map(manageMeetingParticipants1 -> {
                return manageMeetingParticipants1.getParticipants() + "";
            }).collect(Collectors.joining(","));
            record.setParticipant(collect);
        }
        return iPage;
    }
 
    @Override
    public void addMeeting(ManageMeetingDto dto) {
        this.baseMapper.insert(dto);
 
        String[] ids = dto.getParticipant().split(",");
        List<ManageMeetingParticipants> list = new ArrayList<>();
        for (String id : ids) {
            User user = userMapper.selectById(id);
            ManageMeetingParticipants participants = new ManageMeetingParticipants();
            participants.setMeetingId(dto.getId());
            participants.setParticipants(Integer.parseInt(id));
            participants.setDepartment(user.getDepartment());
            list.add(participants);
        }
        list.forEach(v -> manageMeetingParticipantsMapper.insert(v));
    }
 
    @Override
    public int modifyMeeting(ManageMeetingDto manageMeetingDto) {
        this.baseMapper.updateById(manageMeetingDto);
        manageMeetingParticipantsMapper.delete(Wrappers.<ManageMeetingParticipants>lambdaQuery().eq(ManageMeetingParticipants::getMeetingId, manageMeetingDto.getId()));
        String[] ids = manageMeetingDto.getParticipant().split(",");
        List<ManageMeetingParticipants> list = new ArrayList<>();
        for (String id : ids) {
            User user = userMapper.selectById(id);
            ManageMeetingParticipants participants = new ManageMeetingParticipants();
            participants.setMeetingId(manageMeetingDto.getId());
            participants.setParticipants(Integer.parseInt(id));
            participants.setDepartment(user.getDepartment());
            list.add(participants);
        }
        list.forEach(v -> manageMeetingParticipantsMapper.insert(v));
        return 0;
    }
 
    @Override
    public void exportMeeting(Integer id, HttpServletResponse response) {
        ManageMeeting meeting = baseMapper.selectById(id);
        // 查询参加人员
        List<ManageMeetingParticipants> manageMeetingParticipants = manageMeetingParticipantsMapper.selectList(Wrappers.<ManageMeetingParticipants>lambdaQuery().eq(ManageMeetingParticipants::getMeetingId, id));
 
        List<ManageMeetingParticipants> list = manageMeetingParticipants.stream().map(manageMeetingParticipants1 -> {
            manageMeetingParticipants1.setUserName(userMapper.selectById(manageMeetingParticipants1.getParticipants()).getName());
            manageMeetingParticipants1.setDepartment(userMapper.selectUserDepartmentLimsName(manageMeetingParticipants1.getParticipants()));
            return manageMeetingParticipants1;
        }).collect(Collectors.toList());
 
 
        // 创建空对象
        List<ManageMeetingParticipantsDto> participants = new ArrayList<>();
 
        // 添加参加人员
        for (int i = 0; i < list.size(); i++) {
            // 判断有没有到11行
            if (i % 2 == 0) {
                ManageMeetingParticipantsDto manageMeetingParticipantsDto = new ManageMeetingParticipantsDto();
                manageMeetingParticipantsDto.setUserName1(list.get(i).getUserName());
                manageMeetingParticipantsDto.setDepartment1(list.get(i).getDepartment());
                participants.add(manageMeetingParticipantsDto);
            } else {
                participants.get((i-1)/2).setUserName2(list.get(i).getUserName());
                participants.get((i-1)/2).setDepartment2(list.get(i).getDepartment());
            }
        }
 
        InputStream inputStream = this.getClass().getResourceAsStream("/static/review-meet.docx");
 
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        Configure configure = Configure.builder()
                .bind("meetingDetails", new HackLoopTableRenderPolicy())
                .build();
        XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(
                new HashMap<String, Object>() {{
                    put("meeting", meeting);
                    put("meetingTime", meeting.getMeetingTime().format(formatter));
                    put("meetingDetails", participants);
                }});
 
        try {
            response.setContentType("application/msword");
            String fileName = URLEncoder.encode(
                    "管理评审会议记录", "UTF-8");
            response.setHeader("Content-disposition",
                    "attachment;filename=" + fileName + ".docx");
            OutputStream os = response.getOutputStream();
            template.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("导出失败");
        }
    }
}