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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package com.yuanchu.mom.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
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.data.Pictures;
import com.yuanchu.mom.common.GetLook;
import com.yuanchu.mom.dto.InternalMeetingDto;
import com.yuanchu.mom.dto.InternalMeetingParticipantDto;
import com.yuanchu.mom.mapper.UserMapper;
import com.yuanchu.mom.pojo.InternalMeeting;
import com.yuanchu.mom.pojo.InternalMeetingDetail;
import com.yuanchu.mom.pojo.InternalMeeting;
import com.yuanchu.mom.mapper.InternalMeetingMapper;
import com.yuanchu.mom.pojo.User;
import com.yuanchu.mom.service.InternalMeetingDetailService;
import com.yuanchu.mom.service.InternalMeetingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.mom.utils.HackLoopTableRenderPolicy;
import com.yuanchu.mom.utils.DateImageUtil;
import com.yuanchu.mom.utils.QueryWrappers;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 * 内审会议表 服务实现类
 * </p>
 *
 * @author
 * @since 2024-11-12 02:50:44
 */
@Service
@AllArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class InternalMeetingServiceImpl extends ServiceImpl<InternalMeetingMapper, InternalMeeting> implements InternalMeetingService {
 
    private InternalMeetingDetailService internalMeetingDetailService;
    private GetLook getLook;
    private UserMapper userMapper;
 
    /**
     * 内审会议分页查询
     * @param page
     * @param internalMeeting
     * @return
     */
    @Override
    public IPage<InternalMeetingDto> pageInternalMeeting(Page page, InternalMeeting internalMeeting) {
        return baseMapper.pageInternalMeeting(page, QueryWrappers.queryWrappers(internalMeeting));
    }
 
    /**
     * 内审会议新增
     * @param internalMeeting
     * @return
     */
    @Override
    public boolean addInternalMeeting(InternalMeetingDto internalMeeting) {
 
        baseMapper.insert(internalMeeting);
//        // 新增详情
//        for (InternalMeetingDetail internalMeetingDetail : internalMeeting.getMeetingDetailList()) {
//            internalMeetingDetail.setMeetingId(internalMeeting.getMeetingId());
//        }
//        internalMeetingDetailService.saveBatch(internalMeeting.getMeetingDetailList());
        return true;
    }
 
    /**
     * 内审会议修改
     * @param internalMeeting
     * @return
     */
    @Override
    public boolean updateInternalMeeting(InternalMeetingDto internalMeeting) {
        baseMapper.updateById(internalMeeting);
 
        // 删除之前的详情
//        internalMeetingDetailService.remove(Wrappers.<InternalMeetingDetail>lambdaQuery()
//                .eq(InternalMeetingDetail::getMeetingId, internalMeeting.getMeetingId()));
//
//        // 新增详情
//        for (InternalMeetingDetail internalMeetingDetail : internalMeeting.getMeetingDetailList()) {
//            internalMeetingDetail.setMeetingId(internalMeeting.getMeetingId());
//        }
        internalMeetingDetailService.saveBatch(internalMeeting.getMeetingDetailList());
 
        return true;
    }
 
    /**
     * 内审会议删除
     * @param MeetingId
     * @return
     */
    @Override
    public boolean delInternalMeeting(Integer MeetingId) {
        internalMeetingDetailService.remove(Wrappers.<InternalMeetingDetail>lambdaQuery()
                .eq(InternalMeetingDetail::getMeetingId, MeetingId));
        baseMapper.deleteById(MeetingId);
        return true;
    }
 
    /**
     * 内审会议查看详情
     * @param MeetingId
     * @return
     */
    @Override
    public InternalMeetingDto getInternalMeetingOne(Integer MeetingId) {
        InternalMeeting internalMeeting = baseMapper.selectById(MeetingId);
        InternalMeetingDto internalMeetingDto = new InternalMeetingDto();
        BeanUtils.copyProperties(internalMeeting, internalMeetingDto);
 
        // 查询详细信息
        internalMeetingDto.setMeetingDetailList(internalMeetingDetailService.list(Wrappers.<InternalMeetingDetail>lambdaQuery()
                .eq(InternalMeetingDetail::getMeetingId, MeetingId)));
        return internalMeetingDto;
    }
 
    /**
     * 导出内审会议
     * @param meetingId
     * @param response
     */
    @Override
    public void exportInternalMeeting(Integer meetingId, HttpServletResponse response) {
        InternalMeeting internalMeeting = baseMapper.selectById(meetingId);
 
        // 最大行数
        int max = 11;
 
        // 查询参加人员
        List<Map<String, String>> mapList = userMapper.selectNameAnddepartment(internalMeeting.getParticipant());
 
        // 创建空对象
        List<InternalMeetingParticipantDto> participants = new ArrayList<>();
        for (int i = 0; i < max; i++) {
            InternalMeetingParticipantDto participant = new InternalMeetingParticipantDto();
            participants.add(participant);
        }
 
        int count = 0;
        // 添加参加人员
        for (Map<String, String> stringMap : mapList) {
            // 判断有没有到11行
            if (count >= max * 2) {
                participants.get(count - max * 2).setUserName3(stringMap.get("userName"));
                participants.get(count - max * 2).setDepartment3(stringMap.get("department"));
            } else if (count >= max){
                participants.get(count - max).setUserName2(stringMap.get("userName"));
                participants.get(count - max).setDepartment2(stringMap.get("department"));
            } else {
                participants.get(count).setUserName1(stringMap.get("userName"));
                participants.get(count).setDepartment1(stringMap.get("department"));
            }
            count ++;
        }
 
        // 获取路径
        InputStream inputStream = this.getClass().getResourceAsStream("/static/internal-meeting.docx");
        Configure configure = Configure.builder()
                .bind("meetingDetails", new HackLoopTableRenderPolicy())
                .build();
        XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(
                new HashMap<String, Object>() {{
                    put("meeting", internalMeeting);
                    put("meetingDetails", participants);
                }});
 
        try {
            response.setContentType("application/msword");
            String fileName = URLEncoder.encode(
                    internalMeeting.getMeetingDate() + "内审会议签到", "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("导出失败");
        }
 
    }
 
 
}